#P13583. [NWRRC 2023] Colorful Village
[NWRRC 2023] Colorful Village
题目描述
Colorful Village is a popular tourist destination. It has houses, numbered from to . Every house has one of colors, numbered from to . Coincidentally, for each of the colors, exactly two houses are colored into it.
There are bidirectional roads in Colorful Village. Each road connects two different houses, and it is possible to reach any house from any other house using these roads.
Catherine is planning a trip to Colorful Village. Her time is limited, so she wants to choose a set of houses to visit, with exactly one house of each color. However, since Catherine also needs to move between houses, the set of houses she is going to visit must be connected. In other words, it must be possible to reach any house in from any other house in using the roads, and only visiting houses in on the way.
Help Catherine to find a connected set of houses, one of each color, or report that no such set exists.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer ().
The second line contains integers , denoting the colors of the houses in Colorful Village (). Every integer from to appears exactly twice in this line.
The -th of the following lines contains two integers and , denoting the houses connected by the -th road (; ).
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, print a single integer if the required set of houses does not exist.
Otherwise, print distinct integers in any order, denoting a connected set of houses, one of each color (). If there are multiple answers, print any of them.
2
4
1 3 1 3 4 4 2 2
1 6
5 3
2 4
7 1
7 5
5 8
2 5
3
1 1 2 2 3 3
1 2
2 3
3 4
4 5
5 6
2 3 5 7
-1