#P8403. [CCC 2022 J4] Good Groups

[CCC 2022 J4] Good Groups

Background

Please note: this problem is a simplified version of CCO 2022 S2 Good Groups.

Admin note: it seems it is not simplified.

Problem Description

A class will be divided into gg groups, with three students in each group. This grouping may break two kinds of rules:

  1. Some students must be in the same group.
  2. Some students must not be in the same group.

Now the principal asks you how many rules in total are violated by the students.

Input Format

The first line contains an integer xx. The next xx lines each contain two student names name1,name2name_1,name_2, meaning these two students must be assigned to the same group.

Next is an integer yy. The next yy lines each contain two student names name1,name2name_1,name_2, meaning these two students must not be in the same group.

Next is an integer gg. The next gg lines each contain three student names name1,name2,name3name_1,name_2,name_3, meaning these three students are currently in the same group.

Output Format

Output one integer, the total 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:

  1. A\rm A and B\rm B must be in the same group, and this rule is violated.
  2. G\rm G and L\rm L must be in the same group, and this rule is violated.
  3. J\rm J and K\rm K must be in the same group, and this rule is not violated.
  4. D\rm D and F\rm F must not be in the same group, and this rule is violated.
  5. D\rm D and G\rm G must not be in the same group, and this rule is not violated.

Among these 55 rules, 33 are violated, so the output is 33.

Constraints:

For 25%25\% of the testdata: 1g501 \le g \le 50, 1x501 \le x \le 50, y=0y = 0.

For another 60%60\% of the testdata: 1g501 \le g \le 50, 1x501 \le x \le 50, 1y501 \le y \le 50.

For 100%100\% of the testdata: 1g1051 \le g \le 10^5, 1x1051 \le x \le 10^5, 1y1051 \le y \le 10^5.

Translated by ChatGPT 5