Under construction

Still being built. Things may change

Tokens

Time limit2sMemory limit1024 MB

Summary
Given a directed graph and two token placements of equal size, decide whether tokens can move from the red set to the blue set and back to the red set.
Level

Hard9 of 10

Topics
Graph, DFS, Topological sort
Solved
No attempts yet

Problem

Dong-hun gave his friend Chan-kyung a directed graph with NN vertices and MM one-way edges. Along with the graph came two cards, and Chan-kyung realized that Dong-hun had prepared a mission to trick him. The mission is as follows.

  • One of the two cards is red and the other is blue. Each card lists PP vertex numbers from 1 to NN. The numbers on each card are distinct, but one vertex number may appear on both cards. The state where a token sits on every vertex listed on the red card is the 'first state'. The state where a token sits on every vertex listed on the blue card is the 'second state'.
  • Place tokens on the graph to reach the first state.
  • Repeatedly move tokens to reach the second state. If there is an edge from vertex uu to vertex vv, vertex uu has a token, and vertex vv has no token, the token on uu can be moved to vv.
  • Repeatedly move tokens to reach the first state again.

Chan-kyung knows Dong-hun's habits, so he suspects the mission may be impossible from the start. If it is impossible, he will leave and do something else. Help Chan-kyung!

Input

The first line contains the number of vertices NN and the number of one-way edges MM. (1≤N≤200 000,0≤M≤min⁡(N⋅(N−1),200 000))(1 \le N \le 200\,000, 0 \le M \le \min(N \cdot (N - 1), 200\,000))

The next MM lines each contain two integers uiu_i and viv_i, meaning there is a one-way edge from vertex uiu_i to vertex viv_i. The input has no duplicate edges and no self-loops.

The (M+2)(M + 2)-th line contains the number of vertices PP listed on each card. (0≤P≤N)(0 \le P \le N)

The (M+3)(M + 3)-th line contains PP distinct positive integers a1,a2,…,aPa_1, a_2, \ldots, a_P, the vertices listed on the red card. (1≤ai≤N)(1 \le a_i \le N)

The (M+4)(M + 4)-th line contains PP distinct positive integers b1,b2,…,bPb_1, b_2, \ldots, b_P, the vertices listed on the blue card. (1≤bi≤N)(1 \le b_i \le N)

All values on each line are separated by spaces.

Output

Print YES if Chan-kyung can complete the mission, and NO if he cannot.

Examples2

  1. Example 1

    Input
    5 6
    5 2
    2 3
    1 5
    3 4
    5 4
    2 1
    2
    3 5
    1 3
    
    Expected output
    YES
    
  2. Example 2

    Input
    3 2
    1 3
    3 1
    1
    2
    3
    
    Expected output
    NO