Is this a DFS traversal?

You are given an undirected graph with nn vertices (numbered from 0) and mm edges, and a sequence of kk vertices. Can the sequence be the result of a Depth First Search traversal of the graph starting at 0? Please remember that a DFS explores as far as possible along each branch, and backtracks only when the current vertex has already been explored. The neighbours of each vertex can be visited in any order.

Input

Input consists of several cases, each one with nn and mm, followed by the mm edges xx yy, followed by kk, followed by kk different vertices between 0 and n−1n-1. Assume 1≤n≤1041 \le n \le 10^4, 0≤m≤5n0 \le m \le 5n, x≠yx \ne y, that there are no repeated edges, and 1≤k≤n1 \le k \le n.

Output

For every case, print the right answer “yes” or “no”.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:09:27.030Z

© Jutge.org, 2006–2026.
https://jutge.org