#P13583. [NWRRC 2023] Colorful Village

[NWRRC 2023] Colorful Village

题目描述

Colorful Village is a popular tourist destination. It has 2n2n houses, numbered from 11 to 2n2n. Every house has one of nn colors, numbered from 11 to nn. Coincidentally, for each of the nn colors, exactly two houses are colored into it.

There are 2n12n-1 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 SS of nn 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 SS from any other house in SS using the roads, and only visiting houses in SS on the way.

Help Catherine to find a connected set SS of nn 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 tt (1t1051 \le t \le 10^5). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1051 \le n \le 10^5).

The second line contains 2n2n integers c1,c2,,c2nc_1, c_2, \ldots, c_{2n}, denoting the colors of the houses in Colorful Village (1cin1 \le c_i \le n). Every integer from 11 to nn appears exactly twice in this line.

The ii-th of the following 2n12n-1 lines contains two integers uiu_i and viv_i, denoting the houses connected by the ii-th road (1ui,vi2n1 \le u_i, v_i \le 2n; uiviu_i \ne v_i).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

输出格式

For each test case, print a single integer 1-1 if the required set of houses does not exist.

Otherwise, print nn distinct integers s1,s2,,sns_1, s_2, \ldots, s_n in any order, denoting a connected set SS of nn houses, one of each color (1si2n1 \le s_i \le 2n). 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