Escape from... dolls 2 - MarisaOJ: Marisa Online Judge

Escape from... dolls 2

Time limit: 1000 ms
Memory limit: 256 MB
Marisa is again being chased by $k$ Alice's dolls. Marisa is now at vertex $1$ of an undirected graph of $n$ vertices and $m$ edges. The $i^{th}$ doll is at vertex $A_i$. Marisa and dolls can move to any adjacent vertex in $1$ unit of time. Marisa can escape these dolls after reaching one of the $p$ special vertices $S_1,S_2,...,S_p$. She does not want to encounter any doll on her path (encountering the dolls at the special vertices still counts). Determine if there exists a path that **in any case**, Marisa won't meet any doll. ### Input - The first line contains 4 integers $n, m, k, p$. - The second line contains $k$ integers $A_i$. - The third line contains $p$ integers $S_i$. - The next $m$ lines, each line contains 2 integers $u, v$, there is an edge between $u$ and $v$. ### Output - Print `YES` if such a path exists, `NO` otherwise. ### Constraints - $1 \le p,k \le n \le 10^5$. - $1 \le m \le 10^5$. - $1 \le u, v, A_i \le n$. ### Example Input: ``` 6 6 2 1 2 5 6 1 2 1 3 3 4 2 4 4 5 3 6 ``` Output: ``` YES ```