QOJ.ac

QOJ

Limite de temps : 4 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#14224. 橙石网络

Statistiques

敏锐地察觉到商机,你决定通过用橙石连接线连接 $n$ 个村庄,成为一名电信大亨。为了节省成本,你使用了连接所有 $n$ 个村庄所需的最少连接线数量。此外,由于延迟会令人难以忍受,任何两个村庄之间最多通过 $100$ 条连接线相连。

与红石不同,橙石连接线可以被开启和关闭,但只能通过以下方式进行:在一步操作中,你可以选择一个村庄,如果它连接到其他村庄的所有连接线都处于关闭状态,你可以将它们全部开启;或者你可以选择一个村庄,如果它连接到其他村庄的所有连接线都处于开启状态,你可以将它们全部关闭。

帮你建设网络的网络朋友们把事情搞砸了,现在有些连接线是关闭的!现在你需要设计一个操作序列,将所有的连接线都开启。由于你需要在竞争对手出现之前快速行动,你最多可以使用 $50n$ 步操作来开启整个网络。

输入格式

输入的第一行包含一个整数 $n$($2 \le n \le 10^4$),表示村庄的数量。村庄从 $1$ 到 $n$ 进行编号。

接下来的 $n - 1$ 行,每行包含三个空格分隔的整数 $a_i, b_i, s_i$,其中 $1 \le a_i, b_i \le n$ 且 $s_i \in \{0, 1\}$。每行代表 $a_i$ 和 $b_i$ 之间的一条连接线。如果 $s_i = 0$,则该连接线处于关闭状态;如果 $s_i = 1$,则该连接线处于开启状态。

输出格式

输出的第一行,打印一个整数 $m$($0 \le m \le 50n$),表示你将所有连接线开启所需的步数。

接下来的 $m$ 行中,第 $i$ 行打印一个整数 $a_i$,表示你的第 $i$ 步操作是翻转与村庄 $a_i$ 相邻的所有连接线的状态。

可以证明,对于满足上述约束的任何输入,都存在一个步数不超过 $50n$ 的有效操作序列。

样例

输入样例 1

3
2 1 0
3 1 0

输出样例 1

2
2
3

输入样例 2

10
10 5 0
3 9 0
9 7 0
3 2 1
4 5 1
1 7 1
7 10 0
8 7 1
6 2 1

输出样例 2

6
2
4
9
2
10
4

输入样例 3

10
10 3 0
8 1 0
1 2 1
4 8 1
7 5 1
4 9 0
6 5 0
6 10 1
2 7 0

输出样例 3

13
9
4
3
10
6
3
5
10
7
6
3
8
9

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.