#P6698. [BalticOI 2020] 病毒 (Day2)
[BalticOI 2020] 病毒 (Day2)
Description
A virus is given. For convenience, we use the integers from to 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 and , then the mutation of the virus is completed.
The virus can be detected by antibodies. For example, can detect , but it cannot detect .
For genes from to , 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 , representing the number of genes, the number of mutation rules, and the number of antibodies.
In the next lines, each line starts with two integers , followed by integers , meaning that can be transformed by this mutation rule into the fragment . It is guaranteed that both and appear at least once among the values in all rules.
In the next lines, each line starts with an integer representing the antibody length, followed by integers describing the antibody.
Output Format
Output lines. Line corresponds to gene 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 .
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): .
- Subtask 2 (14 pts): .
- Subtask 3 (25 pts): .
- Subtask 4 (32 pts): .
- Subtask 5 (18 pts): No special constraints.
For of the testdata, , , . , , , , , , .
This problem enforces optimization.
Translated by ChatGPT 5
京公网安备 11011102002149号