#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 uu grows too large and is split into two cities vv and ww. The cities originally joined directly to uu by a road are partitioned into sets AA and BB. AA road is built from each city in AA to vv, from each city in BB to ww and from vv to ww. 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 55 marks each.

输入格式

The first line contains a single integer S (1S5)S\ (1 \le S \le 5) representing the subtask which you must solve. The second line contains an integer T (1T)T\ (1 \le T) representing the number of test cases. Each test case consists of a blank line, followed by two integers NN and M (2N,1M)M\ (2 \le N, 1 \le M) representing the number of cities and roads, respectively. The cities are numbered from 11 to NN. Then MM lines follow, each containing two integers aa and b (1a,bN)b\ (1 \le a, b \le N) 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 33, you may assume that the sum of NN over all test cases is at most 10510^5. In all other subtasks, the sum of NN over all test cases is at most 10001\,000.

The same condition holds for MM. In particular, in subtask 33, you may assume that the sum of MM over all test cases is at most 10510^5. In all other subtasks, the sum of MM over all test cases is at most 10001\,000.

输出格式

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 11

Test Case Number Network Explanation
11 matches The Myth of the Flask
22 cannot match The Myth of the Flask

Explanation for Sample Output 22

Test Case Number Network Explanation
11 cannot match The Myth of the Moon
22 matches The Myth of the Moon, since we can add cities 44 and 55 along with some extra roads to the Moon formed by cities 11, 22 and 33.

Explanation for Sample Output 33

Test Case Number Network Explanation
11 can match The Myth of the Sun, on cities 11, 22, 33 and 44
22 can match The Myth of the Sun, on cities 11, 22, 33 and 44 where some new cities have been inserted between cities 11 and 44

Explanation for Sample Output 44

Test Case Number Network Explanation
11 cannot match The Myth of the Talon
22 can match The Myth of the Talon on cities 11, 22, 44 and 66

Explanation for Sample Output 55

Test Case Number Network Explanation
11 cannot match The Myth of the Fox
22 can match The Myth of the Fox, on cities 11, 22, 44, 55 and 66