#P13506. [OOI 2024] Parallel Universes
[OOI 2024] Parallel Universes
题目描述
Berlandia --- a country with a highly developed road system. There are a total of cities in Berlandia, and there is exactly one road between each pair of cities, accessible for travel in both directions.
For the purpose of saving electricity, only roads are illuminated in Berlandia, the -th of which connects cities and . For safety reasons, it is forbidden to travel on unlit roads in Berlandia.
In a parallel universe, there is a similar country called Cherlandia, consisting of cities. There is also exactly one road between each pair of cities in Cherlandia. The countries differ only in their electricity economy: in Cherlandia, roads are illuminated, the -th of which connects cities and . It is known that in Cherlandia, it is possible to travel from any city to any other using only illuminated roads.
You possess a secret spell that allows you to choose any two different cities and and change the illumination on the road between cities and in both universes. That is, in each universe, if the road was not illuminated, it becomes illuminated, and vice versa.
You want to use this spell no more than times in order to make it possible to travel from any city to any other in Berlandia using only illuminated roads. At the same time, after each spell is cast, Cherlandia must remain , that is, there should not exist two cities between which it is impossible to travel on illuminated roads.
Determine if this can be achieved, and if so, find a suitable sequence of spells.
输入格式
Each test consists of several sets of input data. The first line contains two integers and (, ) --- the number of sets of input data and the test group number. This is followed by descriptions of the sets of input data.
The first line of each set of input data description contains three integers , , and (, , ) --- the number of cities, the number of illuminated roads in Berlandia, and the number of illuminated roads in Cherlandia.
The next lines contain descriptions of illuminated roads in Berlandia. The -th line contains two integers and () --- the numbers of cities connected by the -th illuminated road. It is guaranteed that all roads are distinct.
The next lines contain descriptions of illuminated roads in Cherlandia. The -th line contains two integers and () --- the numbers of cities connected by the -th illuminated road. It is guaranteed that all roads are distinct, and that in Cherlandia, there exists a path consisting only of illuminated roads between any two cities.
Let , , and be the sum of , , and for all sets of input data in one test. It is guaranteed that .
输出格式
For each set of input data, output (without quotes) if there is no sequence of spells that satisfies all conditions.
Otherwise, output . On the second line, output an integer () --- the number of spells you have used.
Then output lines. In the -th line, output two integers and (, ) --- the numbers of cities to which the -th spell is applied. Note that after each spell is cast, Cherlandia must remain .
3 0
3 0 3
1 2
2 3
1 3
4 2 3
1 2
3 4
1 3
1 4
2 3
4 3 3
1 2
2 3
1 3
1 4
2 4
3 4
No
Yes
1
2 4
Yes
2
1 2
4 2
提示
Note
In the first set of input data, there is no suitable sequence of spells, so the answer is .
In the second set of input data, the illuminated roads initially have the following structure:
:::align{center}
:::
After casting a spell on cities and in both Berlandia and Cherlandia, this road becomes illuminated, as it was unlit in both countries. After this operation, the countries will have the following structure:
:::align{center}
:::
After this operation, it is possible to travel from any city to any other in Berlandia, so this sequence of spells is correct.
In the third set of input data, after casting a spell on cities and , the road between these two cities in Berlandia ceases to be illuminated, as it was illuminated before. In Cherlandia, on the contrary, the road becomes illuminated. After this operation, the countries will have the following structure:
:::align{center}
:::
After casting a spell on cities and , the countries will have the following structure:
:::align{center}
:::
Scoring
The tests for this problem consist of ten groups. Points for each group are given only if all tests of the group and all tests of the required groups are passed. Please note that passing the example tests is not required for some groups. means that the results of testing your solution on this group will only be available after the end of the competition.
Group | Points | Additional constraints | Required Groups | Comment |
---|---|---|---|---|
0 | -- | -- | Examples. | |
1 | 9 | |||
2 | 7 | |||
3 | 10 | Berlandia consists of two connected components | ||
4 | 11 | There are no isolated cities in Berlandia | ||
5 | 15 | , and for all | ||
6 | 8 | 5 | ||
7 | 12 | -- | In both countries, the road between cities and is illuminated | |
8 | 6 | 0 -- 7 | ||
9 | 8 | -- | -- | , and for all |
10 | 14 | 0 -- 9 | Offline-evaluation. |
Connected component — a set of cities such that there exists a path consisting only of illuminated roads between any pair of them.
A city is called isolated if there is no illuminated road connecting it to any other city.