#P4386. [SHOI2015] 零件组装机

[SHOI2015] 零件组装机

Description

SHTSC, the inventor who once created a laser generator, has now unveiled his new invention: the Parts Assembly Machine — a mysterious device that can produce and assemble parts.

A part is an undirected graph whose vertices are labeled from 00 to n1n-1, and the machine has the following two functions:

  1. Produce a part that has only one vertex labeled 00 and no edges.
  2. Combine two existing parts G1G_1 and G2G_2, with the number of vertices of G2G_2 being mm and greater than or equal to the number of vertices of G1G_1, which is nn, to obtain a new part GG. The vertex set of GG is the union of the vertex sets of G1G_1 and G2G_2, and vertex i(0i<m)i(0\leq i < m) of G2G_2 is relabeled as n+in+i. The edge set of GG is the union of the edge sets of G1G_1 and G2G_2, then for every vertex with label a(an)a(a \geq n), add an undirected edge connecting (a,amodn)(a,a \bmod n).

Now SHTSC is wondering whether a given part can be produced by the machine. Note that parts are labeled, which means two parts are considered different even if they only differ by labels. To help you understand the problem, SHTSC has provided diagrams of all parts with number of vertices 5\le 5.

Input Format

The first line contains an integer tt, the number of test cases.

For each test case, the first line contains two integers nn and mm, indicating a labeled undirected graph with nn vertices labeled from 00 to n1n - 1 and mm edges. Then mm lines follow, each containing two integers u,vu,v, representing an undirected edge between uu and vv.

Output Format

For each test case, output one line. If the undirected graph can be produced by the Parts Assembly Machine, output YES; otherwise, output NO.

3
1 0
2 0
4 6
0 1
0 2
1 2
1 3
2 3
3 0
YES
NO
YES

Hint

For 5%5\% of the testdata, the given graph is connected and m=n1m = n - 1.
For another 15%15\% of the testdata, n5n \leq 5.
For 50%50\% of the testdata, n1000n \leq 1000.
For all test points, t10t \leq 10, n,m100000n, m \leq 100000.

Translated by ChatGPT 5