#P3209. [HNOI2010] 平面图判定
[HNOI2010] 平面图判定
Description
If an undirected graph can be drawn in the plane such that any two edges that do not share an endpoint do not intersect, then is called a planar graph. Deciding whether a graph is planar is an important problem in graph theory. Now suppose you are to decide this for a special class of graphs that contain a cycle passing through all vertices, i.e., there exists a Hamiltonian cycle.
Input Format
The first line of the input file contains a positive integer , indicating the number of test cases (each test case describes one graph to be decided).
Starting from the second line, there are test cases. For each test case, the first line contains two positive integers and separated by a space, representing the number of vertices and the number of edges of the corresponding graph, respectively.
The next lines each contain two positive integers and separated by a space, representing an edge of the graph. The input guarantees that each edge appears exactly once.
The last line of each test case contains integers, from left to right representing a Hamiltonian cycle of the corresponding graph: , i.e., for any we have , and for any we have and .
The input guarantees that of the testdata satisfy , , .
Output Format
Output lines. If the graph in the -th test case is planar, print YES on the -th line; otherwise, print NO. Note that they must be uppercase letters.
2
6 9
1 4
1 5
1 6
2 4
2 5
2 6
3 4
3 5
3 6
1 4 2 5 3 6
5 5
1 2
2 3
3 4
4 5
5 1
1 2 3 4 5
NO
YES
Hint
Thanks to @hibiki for correcting the problem.
Thanks to @Anguei for providing the LaTeX problem statement.
Translated by ChatGPT 5
京公网安备 11011102002149号