QOJ.ac

QOJ

時間限制: 0.7 s 記憶體限制: 256 MB 總分: 100

#5707. 病毒

统计

二进制病毒研究委员会发现了一种大型病毒家族的复制方法,其遗传密码是 0 和 1 的序列。每种病毒都起源于单个基因;为简单起见,基因用 $0$ 到 $G - 1$ 的整数表示。在任何时刻,病毒都是一个基因序列。当发生突变时,根据突变表,序列中的一个基因会被替换为特定的基因序列。当病毒仅由基因 $0$ 和 $1$ 组成时,突变停止。

例如,对于以下突变表:

$2 \to \langle 0 \ 1 \rangle$ $3 \to \langle 2 \ 0 \ 0 \rangle$ $3 \to \langle 1 \ 3 \rangle$ $4 \to \langle 0 \ 3 \ 1 \ 2 \rangle$ $5 \to \langle 2 \ 1 \rangle$ $5 \to \langle 5 \rangle$

一个最初由单个基因 $4$ 组成的病毒,可能按如下方式突变: $\langle 4 \rangle \to \langle 0 \ 3 \ 1 \ 2 \rangle \to \langle 0 \ 2 \ 0 \ 0 \ 1 \ 2 \rangle \to \langle 0 \ 0 \ 1 \ 0 \ 0 \ 1 \ 2 \rangle \to \langle 0 \ 0 \ 1 \ 0 \ 0 \ 1 \ 0 \ 1 \rangle$

或者以另一种方式: $\langle 4 \rangle \to \langle 0 \ 3 \ 1 \ 2 \rangle \to \langle 0 \ 1 \ 3 \ 1 \ 2 \rangle \to \langle 0 \ 1 \ 3 \ 1 \ 0 \ 1 \rangle \to \langle 0 \ 1 \ 2 \ 0 \ 0 \ 1 \ 0 \ 1 \rangle \to \langle 0 \ 1 \ 0 \ 1 \ 0 \ 0 \ 1 \ 0 \ 1 \rangle$

病毒可以通过抗体检测,抗体能识别病毒代码中是否存在特定的连续片段。例如,一种对片段 $\langle 0 \ 0 \ 1 \ 0 \ 0 \rangle$ 反应的抗体将检测到病毒 $\langle 0 \ 0 \ 1 \ 0 \ 0 \ 1 \ 0 \ 1 \rangle$,但它不会检测到病毒 $\langle 0 \ 1 \ 0 \ 1 \ 0 \ 0 \ 1 \ 0 \ 1 \rangle$。

对于从 $2$ 到 $G-1$ 的每个基因,科学家们想知道给定的一组抗体是否足以检测出所有可能由该基因突变产生的病毒。如果不能,他们想知道无法检测到的最短病毒的长度。

有时科学家可能没有任何抗体。在这种情况下,当然无法检测到任何病毒,因此科学家只对由基因突变产生的最短可能病毒的长度感兴趣。

输入格式

输入的第一行包含三个整数 $G, N$ 和 $M$ ($G > 2, N \ge G - 2, M \ge 0$),分别指定基因数量、突变表行数和抗体数量。

接下来的 $N$ 行包含突变表的行描述;每行以两个整数 $a$ 和 $k$ ($2 \le a < G, k \ge 1$) 开头,后跟一个由 $k$ 个整数 $b_1, b_2, \dots, b_k$ ($0 \le b_i < G$) 组成的序列,编码该行: $a \to \langle b_1 \ b_2 \dots b_k \rangle$

所有 $k$ 值的总和不超过 $100$。从 $2$ 到 $G - 1$ 的每个整数在表中至少作为 $a$ 出现一次。

接下来的 $M$ 行包含抗体的描述;每行以一个整数 $\ell$ ($\ell \ge 1$) 开头,后跟一个由 $\ell$ 个整数 $c_1, c_2, \dots, c_\ell$ ($0 \le c_i \le 1$) 组成的序列,描述该抗体。所有 $\ell$ 值的总和不超过 $50$。

输出格式

你的程序需要输出恰好 $G-2$ 行,包含从 $2$ 到 $G - 1$ 的后续基因的答案。

如果所有能从该单个基因突变产生的病毒都能被给定的抗体集检测到,你需要打印单词 “YES”。如果没有任何病毒能从该基因产生(当序列永远不会停止突变时会发生这种情况),你也需要打印 “YES”。

否则,你需要打印单词 “NO”,后跟一个整数,表示无法检测到的病毒的最小长度。你可以假设对于所有准备好的输入数据,该值都将小于 $2^{63}$。

样例

输入 1

6 6 2
2 2 0 1
3 3 2 0 0
3 2 1 3
4 4 0 3 1 2
5 2 2 1
5 1 5
2 1 1
5 0 0 1 0 0

输出 1

NO 2
NO 4
NO 9
YES

子任务

  1. ($11$ 分) 无抗体 ($M = 0$)
  2. ($14$ 分) $N = G - 2$
  3. ($25$ 分) 一个抗体 ($M = 1$)
  4. ($32$ 分) 所有 $\ell$ 值的总和不超过 $10$
  5. ($18$ 分) 无其他限制

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.