#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 to , and the machine has the following two functions:
- Produce a part that has only one vertex labeled and no edges.
- Combine two existing parts and , with the number of vertices of being and greater than or equal to the number of vertices of , which is , to obtain a new part . The vertex set of is the union of the vertex sets of and , and vertex of is relabeled as . The edge set of is the union of the edge sets of and , then for every vertex with label , add an undirected edge connecting .

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 .

Input Format
The first line contains an integer , the number of test cases.
For each test case, the first line contains two integers and , indicating a labeled undirected graph with vertices labeled from to and edges. Then lines follow, each containing two integers , representing an undirected edge between and .
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 of the testdata, the given graph is connected and .
For another of the testdata, .
For of the testdata, .
For all test points, , .
Translated by ChatGPT 5
京公网安备 11011102002149号