CF1559C.Mocha and Hiking

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

There are two kinds of roads:

  • n−1n-1 roads are from village ii to village i+1i+1, for all 1≤i≤n−11\leq i \leq n-1.
  • nn roads can be described by a sequence a1,…,ana_1,\ldots,a_n. If ai=0a_i=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 1≤i≤n1\leq i\leq 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?

Mocha 所居住的城市名为之江。该城市共有 n+1n+1 个村庄和 2n−12n-1 条有向道路。

道路分为两类:

  • n−1n-1 条道路,对所有 1≤i≤n−11\leq i \leq n-1,从村庄 ii 指向村庄 i+1i+1;
  • nn 条道路可由一个序列 a1,…,ana_1,\ldots,a_n 描述:对所有 1≤i≤n1\leq i\leq n,若 ai=0a_i=0,则第 ii 条此类道路从村庄 ii 指向村庄 n+1n+1;否则(即 ai=1a_i=1),该道路从村庄 n+1n+1 指向村庄 ii。

本周末,Mocha 计划与 Taki 一同徒步旅行。为避免旅途单调乏味,他们希望恰好经过每个村庄一次(即寻找一条哈密顿路径)。起点和终点可以是任意村庄。你能帮他们制定出行计划吗?

输入格式

Each test contains multiple test cases.

The first line contains a single integer tt (1≤t≤201 \le t \le 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 (1≤n≤1041 \le n \le 10^4) — indicates that the number of villages is n+1n+1.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤10 \le a_i \le 1). If ai=0a_i=0, it means that there is a road from village ii to village n+1n+1. If ai=1a_i=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 10410^4.

每个测试包含多个测试用例。

第一行包含一个整数 tt(1≤t≤201 \le t \le 20),表示测试用例的数量。每个测试用例由两行组成。

每个测试用例的第一行包含一个整数 nn(1≤n≤1041 \le n \le 10^4),表示村庄数量为 n+1n+1。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤10 \le a_i \le 1)。若 ai=0a_i = 0,表示存在一条从村庄 ii 到村庄 n+1n+1 的道路;若 ai=1a_i = 1,表示存在一条从村庄 n+1n+1 到村庄 ii 的道路。

保证所有测试用例的 nn 值之和不超过 10410^4。

输出格式

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.

对于每个测试用例,输出一行包含 n+1n+1 个整数,其中第 ii 个数表示他们将依次经过的第 ii 个村庄。如果不存在满足条件的答案,则输出 −1-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 (1→4→2→3)(1 \to 4 \to 2 \to 3), (1→2→3→4)(1 \to 2 \to 3 \to 4).

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

So all possible answers are (4→1→2→3)(4 \to 1 \to 2 \to 3), (1→2→3→4)(1 \to 2 \to 3 \to 4), (3→4→1→2)(3 \to 4 \to 1 \to 2), (2→3→4→1)(2 \to 3 \to 4 \to 1).

在第一个测试用例中,该城市如下图所示:

因此所有可能的答案为 (1→4→2→3)(1 \to 4 \to 2 \to 3)、(1→2→3→4)(1 \to 2 \to 3 \to 4)。

在第二个测试用例中,该城市如下图所示:

因此所有可能的答案为 (4→1→2→3)(4 \to 1 \to 2 \to 3)、(1→2→3→4)(1 \to 2 \to 3 \to 4)、(3→4→1→2)(3 \to 4 \to 1 \to 2)、(2→3→4→1)(2 \to 3 \to 4 \to 1)。

输入解题思路,AI测评打分。不知道怎么写?

首页