#P11155. 【MX-X6-T1】 Subtask Dependency
【MX-X6-T1】 Subtask Dependency
Background
Original problem link: https://oier.team/problems/X6B.
Problem Description
There is an OI problem. This problem has subtasks, numbered from to . Subtask depends on subtasks, whose numbers are . It is guaranteed that for all , we have , i.e., a subtask only depends on subtasks with smaller numbers than itself. Note that a subtask may depend on no subtasks.
A contestant's program can be described as a length- sequence , indicating whether the program can pass subtask .
When judging a program, the judge will consider each subtask in increasing order of its number. When considering subtask :
- If among the subtasks it depends on, there exists a subtask whose status is wrong, then the status of subtask is wrong.
- Otherwise, the judge tests this subtask. If the contestant's program can pass this subtask, then the status of this subtask is correct; otherwise, it is wrong.
The score of a program is the number of subtasks whose final status is correct after judging.
Now there are contestants who submitted programs. You need to compute their scores separately.
Input Format
The first line contains an integer , the number of subtasks.
The next lines: on the -th line, first input an integer , the number of subtasks that subtask depends on; then input integers , the indices of the dependent subtasks. It is guaranteed that all .
The next line contains an integer , the number of contestant programs.
The next lines: each line contains integers. On the -th line, the -th integer is meaning the -th contestant's program cannot pass subtask , and meaning it can pass subtask .
Output Format
Output lines. On the -th line, output the score of the -th contestant.
3
0
1 1
1 2
3
1 1 1
1 0 1
0 0 0
3
1
0
10
0
1 1
1 2
3 1 2 3
4 1 4 2 3
0
5 6 4 5 2 1
0
1 4
1 9
10
1 0 0 1 1 0 1 0 0 0
1 0 1 0 1 0 1 0 1 0
1 0 1 1 1 1 1 1 0 1
1 1 0 1 1 0 1 1 0 1
1 1 0 1 0 0 0 1 1 1
1 1 0 1 0 1 0 1 1 1
1 0 0 1 0 1 1 1 0 1
1 1 0 1 1 1 0 0 1 1
1 1 1 0 0 0 0 0 1 1
1 0 0 0 1 1 1 0 1 1
1
1
3
3
3
4
3
3
3
2
Hint
Sample Explanation #1
- Contestant 1's program can pass all subtasks, so the results of all subtasks are correct.
- Contestant 2's program cannot pass subtask , so subtask will be judged as wrong. Since subtask depends on subtask , even if contestant 2's program can pass subtask , subtask will still be judged as wrong. This contestant's judging result has only subtask correct.
- Contestant 3's program cannot pass any subtask, so the results of all subtasks are wrong.
Constraints
For all testdata, , , , , and there do not exist and such that .
There are test groups in total, with the specific limits as follows:
- For test groups , .
- For test groups , for all , .
- For the other test groups, there are no additional constraints.
Translated by ChatGPT 5