[Solution] Mocha and Hiking solution codeforces

Mocha and Hiking solution codeforces


The city where Mocha lives in is called Zhijiang. There are n+1n+1 villages and 2n12n−1 directed roads in this city.

There are two kinds of roads:

  • n1n−1 roads are from village ii to village i+1i+1, for all 1in11≤i≤n−1.
  • nn roads can be described by a sequence a1,,ana1,…,an. If ai=0ai=0, the ii-th of these roads goes from village ii to village n+1n+1, otherwise it goes from village n+1n+1 to village ii, for all 1in1≤i≤n.

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?

Input Mocha and Hiking solution codeforces

Each test contains multiple test cases.

The first line contains a single integer tt (1t201≤t≤20) — the number of test cases. Each test case consists of two lines.

The first line of each test case contains a single integer nn (1n1041≤n≤104) — indicates that the number of villages is n+1n+1.

The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (0ai10≤ai≤1). If ai=0ai=0, it means that there is a road from village ii to village n+1n+1. If ai=1ai=1, it means that there is a road from village n+1n+1 to village ii.

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

Output Mocha and Hiking solution codeforces

For each test case, print a line with n+1n+1 integers, where the ii-th number is the ii-th village they will go through. If the answer doesn’t exist, print 1−1.

If there are multiple correct answers, you can print any one of them.

Example
input

Copy
2
3
0 1 0
3
1 1 0
output Mocha and Hiking solution codeforces

Copy Mocha and Hiking solution codeforces
1 4 2 3 
4 1 2 3 
Note

In the first test case, the city looks like the following graph:

Mocha and Hiking solution codeforces

So all possible answers are (1423)(1→4→2→3)(1234)(1→2→3→4).

In the second test case, the city looks like the following graph:

So all possible answers are (4123)(4→1→2→3)(1234)(1→2→3→4)(3412)(3→4→1→2)(2341)(2→3→4→1).

 

Solution: Click here

 

Leave a Comment