#P8396. Counting Rule Violations in Student Grouping
Counting Rule Violations in Student Grouping
Counting Rule Violations in Student Grouping
A class is divided into \(g\) groups, each consisting of 3 students (i.e. the total number of students is \(3g\)). The grouping is fixed: student \(i\) is assigned to group \(\left\lfloor\frac{i-1}{3}\right\rfloor+1\).
There are two types of rules provided by the administration:
- Certain students must be in the same group.
- Certain students must not be in the same group.
For each rule, if its condition is not satisfied then it is counted as a violation. In detail, for a same-group rule, the rule is satisfied if all the listed students are in the same group, and for a different-group rule, the rule is satisfied if no two of the listed students share the same group.
Your task is to count the total number of violated rules.
inputFormat
The input consists of several parts:
- The first line contains an integer \(g\), representing the number of groups.
- The second line contains an integer \(m\), the number of same-group rules.
- Then \(m\) lines follow. Each line starts with an integer \(s\) (\(s \ge 2\)), the number of students in the rule, followed by \(s\) space separated integers denoting the student IDs.
- Next, a line contains an integer \(k\), the number of different-group rules.
- Then \(k\) lines follow. Each line starts with an integer \(s\) (\(s \ge 2\)), the number of students in the rule, followed by \(s\) space separated integers denoting the student IDs.
Note: Student IDs are numbered from 1 to \(3g\). The grouping is fixed: student \(i\) is in group \(\left\lfloor\frac{i-1}{3}\right\rfloor+1\).
outputFormat
Output a single integer representing the total number of rules that are violated.
sample
2
2
3 1 2 3
2 4 5
2
2 2 3
3 1 5 6
2
</p>