QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#16276. Planarity Testing

统计

A graph $G=(V,E)$ is called a planar graph if it can be drawn in the plane such that no two edges intersect except at their endpoints.

Determining whether a graph is planar is an important problem in graph theory. Now, assume that the graph you need to determine is a special type of graph that contains a Hamiltonian cycle, i.e., a cycle that visits every vertex exactly once.

Input

The first line of the input contains a positive integer $T$, representing the number of test cases. Each test case begins with a line containing two space-separated positive integers $N$ and $M$, representing the number of vertices and edges in the graph, respectively.

The following $M$ lines each contain two space-separated positive integers $u$ and $v$ ($1 \le u,v \le N$), representing an edge $(u,v)$ in the graph. It is guaranteed that each edge appears only once.

The last line of each test case contains $N$ space-separated positive integers, representing a Hamiltonian cycle in the graph from left to right: $V_1, V_2, \ldots, V_N$. This means that for any $i \ne j$, $V_i \ne V_j$, and for any $1 \le i \le N-1$, $(V_i, V_{i+1}) \in E$, and $(V_1, V_N) \in E$.

It is guaranteed that $100\%$ of the data satisfies $T \le 100$, $3 \le N \le 200$, and $M \le 10000$.

Output

The output contains $T$ lines. If the graph corresponding to the $i$-th test case is a planar graph, output YES on the $i$-th line; otherwise, output NO. Note that these must be in uppercase.

Examples

Input 1

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

Output 1

NO
YES

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.