You are given an undirected graph with vertices (numbered from 0) and edges, and a sequence of 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 consists of several cases, each one with and , followed by the edges , followed by , followed by different vertices between 0 and . Assume , , , that there are no repeated edges, and .
For every case, print the right answer “yes” or
“no”.
Input
8 5 5 0 4 5 0 2 6 1 5 7 5 0 2 5 7 4 4 4 0 1 1 2 2 3 3 0 4 0 1 3 2 4 4 0 2 2 3 3 1 1 2 4 0 2 3 1
Output
yes no yes