#P6698. [BalticOI 2020] 病毒 (Day2)

[BalticOI 2020] 病毒 (Day2)

Description

A virus is given. For convenience, we use the integers from 00 to G1G-1 to describe its gene sequence.

Now this virus can mutate. There are some mutation rules. Each mutation rule can replace a number in the gene sequence with a certain fragment. If, by applying mutation rules, the gene sequence becomes a sequence consisting only of 00 and 11, then the mutation of the virus is completed.

The virus can be detected by antibodies. For example, 0101101011 can detect 01011100101110, but it cannot detect 110110110110.

For genes from 22 to G1G-1, scientists want to know whether any given set of antibodies can detect all other genes that can be formed by mutations from this gene. If not, find the minimum length among the genes that cannot be detected.

Input Format

The first line contains three integers G,N,MG, N, M, representing the number of genes, the number of mutation rules, and the number of antibodies.

In the next NN lines, each line starts with two integers a,ka, k, followed by kk integers bib_i, meaning that aa can be transformed by this mutation rule into the fragment b1,b2,,bkb_1, b_2, \cdots, b_k. It is guaranteed that both 22 and G1G-1 appear at least once among the aa values in all rules.

In the next MM lines, each line starts with an integer ll representing the antibody length, followed by ll integers cic_i describing the antibody.

Output Format

Output G2G-2 lines. Line ii corresponds to gene ii and all genes it can mutate into. If all of them can be detected by any given set of antibodies, output the string YES. Otherwise, output the string NO first, followed by an integer representing the minimum length among the genes that cannot be detected. It is guaranteed that for all testdata, this value is less than 2632^{63}.

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
NO 2
NO 4
NO 9
YES

Hint

Constraints

This problem uses bundled tests.

  • Subtask 1 (11 pts): M=0M=0.
  • Subtask 2 (14 pts): N=G2N = G-2.
  • Subtask 3 (25 pts): M=1M=1.
  • Subtask 4 (32 pts): l10\sum l \le 10.
  • Subtask 5 (18 pts): No special constraints.

For 100%100\% of the testdata, G>2G > 2, NG2N \ge G-2, M0M \ge 0. 2a<G2 \le a <G, k1k \ge 1, 0bi<G0 \le b_i<G, k100\sum k \le 100, l1l \ge 1, 0ci10 \le c_i \le 1, l50\sum l\le 50.

This problem enforces O2O2 optimization.

Translated by ChatGPT 5