#P11155. Dependency Scoring
Dependency Scoring
Dependency Scoring
You are given an OI-style problem consisting of n subtasks (numbered from 1 to n). The i-th subtask depends on d_i subtasks with indices a_{i,1}, a_{i,2}, \dots, a_{i,d_i} (note that for every dependency, we have \(a_{i,j} < i\)). A participant's program is represented by a binary sequence \(p_1, p_2, \dots, p_n\) where \(p_i = 1\) means the program passes subtask i when tested, and \(p_i = 0\) otherwise.
The evaluation is performed in order from subtask 1 to subtask n as follows:
- For subtask \(i\), if any of its dependency subtasks (i.e. those in \(\{a_{i,1}, a_{i,2}, \dots, a_{i,d_i}\}\)) has been marked as incorrect, then subtask \(i\) is automatically marked incorrect.
- Otherwise, subtask \(i\) is tested: if \(p_i=1\), then it is marked correct; if \(p_i=0\), it is marked incorrect.
A program's score is the number of subtasks marked correct after evaluation. Given m submissions, compute the score of each submission.
inputFormat
The first line contains two integers \(n\) and \(m\) \( (1 \leq n, m \leq 10^5) \), representing the number of subtasks and the number of submissions, respectively.
The next \(n\) lines describe the dependencies of the subtasks. The i-th of these lines begins with an integer \(d_i\) (the number of dependencies for subtask \(i\)), followed by \(d_i\) integers \(a_{i,1}, a_{i,2}, \dots, a_{i,d_i}\) with \(a_{i,j} < i\) for all valid \(j\).
Each of the next \(m\) lines contains \(n\) integers \(p_1, p_2, \dots, p_n\) (each either 0 or 1), representing a submission.
outputFormat
Output \(m\) lines. Each line should contain a single integer — the score of the corresponding submission.
sample
5 3
0
1 1
2 1 2
1 2
2 3 4
1 1 1 1 1
1 0 1 1 1
0 1 1 1 1
5
1
0
</p>