#P1559C. Mocha and Hiking
Mocha and Hiking
Mocha and Hiking
题面翻译
给定一张 个点 条边的图,其中边分两种:
- 对于所有 ,存在一条由节点 连向节点 的边;
- 对于所有 ,存在一条由节点 连向节点 的边或者一条由节点 连向节点 的边。
请你输出一种从任意一个点开始遍历所有点的方案,若无法遍历则输出 。
译者 @ajthreac
题目描述
The city where Mocha lives in is called Zhijiang. There are villages and directed roads in this city.
There are two kinds of roads:
- roads are from village to village , for all .
- roads can be described by a sequence . If , the -th of these roads goes from village to village , otherwise it goes from village to village , for all .
Mocha plans to go hiking with Taki this weekend. To avoid the trip being boring, they plan to go through every village exactly once. They can start and finish at any villages. Can you help them to draw up a plan?
输入格式
Each test contains multiple test cases.
The first line contains a single integer ( ) — the number of test cases. Each test case consists of two lines.
The first line of each test case contains a single integer ( ) — indicates that the number of villages is .
The second line of each test case contains integers ( ). If , it means that there is a road from village to village . If , it means that there is a road from village to village .
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, print a line with integers, where the -th number is the -th village they will go through. If the answer doesn't exist, print .
If there are multiple correct answers, you can print any one of them.
样例 #1
样例输入 #1
2
3
0 1 0
3
1 1 0
样例输出 #1
1 4 2 3
4 1 2 3
提示
In the first test case, the city looks like the following graph:
So all possible answers are , .
In the second test case, the city looks like the following graph:
So all possible answers are , , , .