Universal Cup Judging System

Universal Cup

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100
统计

AA 国是一个繁荣的国家,由 $n$ 个城市(编号为 $1$ 到 $n$)和 $n-1$ 条道路组成。由于道路设计良好,你可以从任何城市出发,通过若干条道路到达你想要去的目的地。

AA 国的国王 Dreamoon 明天想要视察所有城市的治安情况,因此他制定了一个路线计划。该计划包含一条经过 $2 \times n - 2$ 条边的路径,起点和终点均为城市 $1$(AA 国的首都)。为了方便记录,Dreamoon 按顺序将路径上的城市编号写在了纸上。

然而,不幸的是,Dreamoon 把奶茶洒在了纸上,导致现在有一些连续的数字看不清了。因此,他请求你帮助恢复这些模糊的数字,以便他能顺利完成旅程。

如果有多种方案,请输出字典序最小的方案。此外,题目保证对于给定的输入至少存在一种解。

输入格式

第一行包含一个整数 $T$,表示测试用例的数量。接下来是各测试用例的描述。

每个测试用例包含两行。第一行包含一个整数 $n$,表示 AA 国的城市数量。第二行包含 $2 \times n - 1$ 个介于 $0$ 到 $n$ 之间的整数,第 $i$ 个数字表示路径上的第 $i$ 个城市。如果第 $i$ 个数字为 $0$,则表示该数字因奶茶污渍而无法看清。输入保证所有 $0$ 是连续的,且至少存在一个 $0$。

数据范围

  • $1 \le T \le 30,000$。
  • $1 \le n \le 300,000$。
  • 城市编号为 $1$ 到 $n$。
  • Dreamoon 写在纸上的数字中至少有一个不清晰,且所有不清晰的数字都是连续的。
  • 所有测试用例的 $n$ 之和不超过 $300,000$。

输出格式

对于每个测试用例,请输出一行,包含 $2 \times n - 1$ 个介于 $1$ 到 $n$ 之间的数字,表示你恢复后的路径。如果存在多种方案,请记住输出字典序最小的那一个。题目保证对于给定的输入至少存在一种解。

样例

输入 1

9
5
1 2 3 2 0 2 1 5 1
5
1 2 3 0 0 2 1 5 1
5
1 2 0 0 0 2 1 5 1
5
1 2 0 0 0 0 1 5 1
5
1 0 0 0 0 0 1 5 1
5
1 0 0 0 0 0 0 5 1
5
1 0 0 0 0 0 0 0 1
5
1 0 0 0 0 0 0 0 0
5
0 0 0 0 0 0 0 0 0

输出 1

1 2 3 2 4 2 1 5 1
1 2 3 2 4 2 1 5 1
1 2 3 2 4 2 1 5 1
1 2 1 3 1 4 1 5 1
1 2 1 3 1 4 1 5 1
1 2 1 3 1 4 1 5 1
1 2 1 3 1 4 1 5 1
1 2 1 3 1 4 1 5 1
1 2 1 3 1 4 1 5 1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.