QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 32 MB 總分: 100

#11879. 大门

统计

考虑一个由 $n$ 个门组成的电路。门的编号从 $0$ 到 $n-1$。每个门都有一定数量的输入和恰好一个输出。它们(输入和输出)中的每一个都可能处于 $0$、$1$ 或 $1/2$ 三种状态之一。每个输入都连接到某个门的恰好一个输出。输入的状态等于它所连接的输出的状态。每个输出可以连接到任意数量的输入。编号为 $0$ 和 $1$ 的门是特殊的——它们没有任何输入,而它们的输出状态始终固定:编号为 $0$ 的门输出为 $0$,编号为 $1$ 的门输出为 $1$。我们称一个门的输出状态(简称:门的状态)是合法的,如果:

  • 它等于 $0$,且该门处于状态 $0$ 的输入数量多于处于状态 $1$ 的输入数量。
  • 它等于 $1/2$,且该门处于状态 $0$ 的输入数量与处于状态 $1$ 的输入数量相等。
  • 它等于 $1$,且该门处于状态 $1$ 的输入数量多于处于状态 $0$ 的输入数量。
  • 该门是特殊的,即编号为 $0$ 或 $1$,且其状态分别为 $0$ 或 $1$。

如果电路中所有门的状态都是合法的,我们称该电路的状态是合法的。如果一个门在所有合法的电路状态中都处于相同的状态,我们称该门的状态是固定的。

编写一个程序:

  • 从标准输入读取电路的描述,
  • 对于每个门,检查其状态是否固定,如果是,则确定该状态,
  • 将确定的门状态写入标准输出。

输入格式

标准输入的第一行包含门的数量 $n$,$2 \le n \le 10\,000$。接下来的 $n-2$ 行包含门连接的描述——第 $i$ 行描述编号为 $i$ 的门的输入。该行首先是该门的输入数量 $k_i$,随后是 $k_i$ 个门的编号,$k_i \ge 1$。这些编号代表其输出连接到编号为 $i$ 的门的相应输入的门。每行中的数字由单个空格分隔。所有门的总输入数量不超过 $200\,000$。

输出格式

你的程序应向标准输出写入 $n$ 行。根据编号为 $i-1$ 的门的状态,第 $i$ 行应包含:

  • 0 - 如果状态已确定且等于 $0$,
  • 1/2 - 如果状态已确定且等于 $1/2$,
  • 1 - 如果状态已确定且等于 $1$,
  • ? - 如果状态未确定。

样例

输入 1

5
2 0 1
2 4 2
2 2 4

输出 1

0
1
1/2
?
?

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.