#P16009. [CCO 2016 Day 1] Legends
[CCO 2016 Day 1] Legends
题目描述
The country of Canadia consists of a network of cities and roads. Each road can be traversed in both directions. It is possible to get from any city to any other city using the roads.
Suzie studies the creation myths of the Canadiaan people. She is particularly interested in five myths (which correspond to the five subtasks of this problem). The myths are very similar. Each myth has the following form:
In the beginning, Canadia's road network had a particular structure. As time went on, the network was modified to meet the needs of Canadia's growing population. Each modification had one of the following forms:
- A road was built between two cities that did not yet have a road going directly between them.
- A new city was built. Cities built in this way were not initially connected to any existing cities.
- A city grows too large and is split into two cities and . The cities originally joined directly to by a road are partitioned into sets and . road is built from each city in to , from each city in to and from to . For example,
becomes
The five myths only differ in the structure that they believe Canadia began with. Here are the original structures, according to each myth:
| Subtask 1 [The Myth of the Flask] | Subtask 2 [The Myth of the Moon] |
|---|---|
![]() |
![]() |
| Subtask 3 [The Myth of the Sun] | Subtask 4 [The Myth of the Eagle's Talon] |
![]() |
![]() |
| Subtask 5 [The Myth of the Fox] | < |
![]() |
For each subtask, you must take the layout of Canadia as input and determine whether the myth might be correct.
Subtasks are worth marks each.
输入格式
The first line contains a single integer representing the subtask which you must solve. The second line contains an integer representing the number of test cases. Each test case consists of a blank line, followed by two integers and representing the number of cities and roads, respectively. The cities are numbered from to . Then lines follow, each containing two integers and representing two cities connected by a road. No road connects a city to itself. No two roads connect the same pair of cities. It is possible to get from any city to any other city using the roads.
In subtask , you may assume that the sum of over all test cases is at most . In all other subtasks, the sum of over all test cases is at most .
The same condition holds for . In particular, in subtask , you may assume that the sum of over all test cases is at most . In all other subtasks, the sum of over all test cases is at most .
输出格式
For each test case, output a single line containing the string YES or the string NO.
1
2
4 5
1 2
2 3
3 4
1 3
2 4
7 8
1 2
2 3
3 4
4 1
4 5
5 6
6 7
7 4
YES
NO
2
2
2 1
1 2
5 6
1 3
5 1
2 3
4 5
1 2
3 5
NO
YES
3
2
7 8
1 2
2 3
3 4
4 1
4 5
5 6
6 7
7 4
8 8
1 2
2 3
3 4
4 5
5 6
6 1
7 3
8 7
YES
YES
4
2
4 4
1 2
2 3
3 4
4 1
6 6
1 2
2 3
1 4
4 5
2 4
1 6
NO
YES
5
2
5 5
1 2
2 3
2 4
4 5
3 5
6 6
1 2
2 3
1 4
4 5
2 4
1 6
NO
YES
提示
Explanation for Sample Output
| Test Case Number | Network | Explanation |
|---|---|---|
![]() |
matches The Myth of the Flask | |
![]() |
cannot match The Myth of the Flask |
Explanation for Sample Output
| Test Case Number | Network | Explanation |
|---|---|---|
![]() |
cannot match The Myth of the Moon | |
![]() |
matches The Myth of the Moon, since we can add cities and along with some extra roads to the Moon formed by cities , and . |
Explanation for Sample Output
| Test Case Number | Network | Explanation |
|---|---|---|
![]() |
can match The Myth of the Sun, on cities , , and | |
![]() |
can match The Myth of the Sun, on cities , , and where some new cities have been inserted between cities and |
Explanation for Sample Output
| Test Case Number | Network | Explanation |
|---|---|---|
![]() |
cannot match The Myth of the Talon | |
![]() |
can match The Myth of the Talon on cities , , and |
Explanation for Sample Output
| Test Case Number | Network | Explanation |
|---|---|---|
![]() |
cannot match The Myth of the Fox | |
![]() |
can match The Myth of the Fox, on cities , , , and |












