#P8396. [CCC 2022 S2] Good Groups
[CCC 2022 S2] Good Groups
Background
Please note: This problem is an advanced version of CCO 2022 J4 Good Groups.
Admin note: It seems there is no enhancement.
Problem Description
A class will be divided into groups, with three students in each group. This grouping may violate two kinds of rules:
- Some students must be in the same group.
- Some students must not be in the same group.
Now the principal asks you how many rules are violated by the students.
Input Format
The first line contains an integer .
The next lines each contain two student names , meaning these two students must be assigned to the same group.
Then there is an integer .
The next lines each contain two student names , meaning these two students must not be in the same group.
Then there is an integer .
The next lines each contain three student names , meaning these three students are currently in the same group.
Output Format
Output one integer, the number of rules violated by the students.
1
ELODIE CHI
0
2
DWAYNE BEN ANJALI
CHI FRANCOIS ELODIE
0
3
A B
G L
J K
2
D F
D G
4
A C G
B D F
E H I
J K L
3
Hint
Explanation for Sample 2:
- and must be in the same group, and this rule is violated.
- and must be in the same group, and this rule is violated.
- and must be in the same group, and this rule is not violated.
- and must not be in the same group, and this rule is violated.
- and must not be in the same group, and this rule is not violated.
Among these rules, are violated, so the output is .
For of the testdata: , , .
For another of the testdata: , , .
For of the testdata: , , .
Translated by ChatGPT 5