Colorful Village

시간 제한2초메모리 제한1024 MB

요약
각 색이 정확히 두 번씩 나타나도록 색칠된 2n개 정점의 트리에서, 모든 색을 하나씩 포함하는 연결된 n개 정점 집합을 찾거나 존재하지 않음을 판정한다.
난이도

어려움10점 중 8점

유형
트리, 그리디, DFS
정답자
아직 제출이 없습니다

문제

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 2n−12n-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 (1≤t≤1051 \le t \le 10^5). The description of the test cases follows.

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

The second line contains 2n2n integers c_1,c_2,…,c_2nc\_1, c\_2, \ldots, c\_{2n}, denoting the colors of the houses in Colorful Village (1≤c_i≤n1 \le c\_i \le n). Every integer from 11 to nn appears exactly twice in this line.

The ii-th of the following 2n−12n-1 lines contains two integers u_iu\_i and v_iv\_i, denoting the houses connected by the ii-th road (1≤u_i,v_i≤2n1 \le u\_i, v\_i \le 2n; u_i≠v_iu\_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 s_1,s_2,…,s_ns\_1, s\_2, \ldots, s\_n in any order, denoting a connected set SS of nn houses, one of each color (1≤s_i≤2n1 \le s\_i \le 2n). If there are multiple answers, print any of them.

예제1

  1. 예제 1

    입력
    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