QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#15597. Part Assembly Machine

Statistics

The inventor SHTSC, who once invented a laser generator, has now unveiled his new invention: the Component Assembly Machine—a mysterious device that can produce and assemble components.

A component is an undirected graph with vertices labeled from $0$ to $n-1$. The Component Assembly Machine has the following two functions:

(1) Produce a component consisting of only one vertex labeled $0$ with no edges.

(2) Combine two existing components $G_1$ and $G_2$, where the number of vertices $m$ in $G_2$ is greater than or equal to the number of vertices $n$ in $G_1$, to obtain a new component $G$. The vertex set of $G$ is the union of the vertex sets of $G_1$ and $G_2$, and the vertices $i$ ($0 \le i < m$) of $G_2$ are re-labeled as $n+i$. The edge set of $G$ is the union of the edge sets of $G_1$ and $G_2$, with an additional undirected edge added between every vertex $a$ ($a \ge n$) and the vertex $(a \pmod n)$.

SHTSC is now wondering whether a given component can be produced and assembled by the Component Assembly Machine.

Note: Components are labeled, which means two components are considered different even if they only differ in their labels.

Input

The first line contains an integer $t$, representing the number of test cases.

For each test case, the first line contains two integers $n$ and $m$, representing that the labeled undirected graph has $n$ vertices labeled $0$ to $n-1$, and $m$ is the number of edges.

The next $m$ lines each contain two integers $u$ and $v$, representing an undirected edge between $u$ and $v$.

Output

For each test case, output a single line. If the undirected graph can be produced by the Component Assembly Machine, output "YES", otherwise output "NO".

Constraints

  • For 10% of the data: $t=1$.
  • For 50% of the data: $n \le 1000$.
  • For 100% of the data: $t \le 10$, $n, m \le 100000$, $0 \le u, v < n$.

Examples

Input 1

2
1 0
2 0

Output 1

YES
NO

Input 2

2
3 3
0 1
0 2
1 2
4 6
0 1
1 2
2 3
3 0
0 2
1 3

Output 2

YES
YES

Input 3

2
5 8
0 1
0 2
0 3
0 4
1 2
1 3
3 4
4 2
5 8
4 0
4 1
4 2
4 3
0 1
0 3
2 1
3 2

Output 3

YES
NO

Note

Example 1: The case $n=1$ and a component that cannot be produced.

Example 2: The case $n=3$ and the second case for $n=4$.

Example 3: The first case for $n=5$ and an example that cannot be produced due to incorrect labeling.

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.