P8403 [CCC 2022 J4] Good Groups

Background

Please note: this problem is a simplified version of [CCO 2022 S2 Good Groups](https://www.luogu.com.cn/problem/P8396). Admin note: it seems it is not simplified.

Description

A class will be divided into $g$ 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 $x$. The next $x$ lines each contain two student names $name_1,name_2$, meaning these two students must be assigned to the same group. Next is an integer $y$. The next $y$ lines each contain two student names $name_1,name_2$, meaning these two students must not be in the same group. Next is an integer $g$. The next $g$ lines each contain three student names $name_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.

Explanation/Hint

### Explanation for Sample 2: 1. $\rm A$ and $\rm B$ must be in the same group, and this rule is violated. 2. $\rm G$ and $\rm L$ must be in the same group, and this rule is violated. 3. $\rm J$ and $\rm K$ must be in the same group, and this rule is not violated. 4. $\rm D$ and $\rm F$ must not be in the same group, and this rule is violated. 5. $\rm D$ and $\rm G$ must not be in the same group, and this rule is not violated. Among these $5$ rules, $3$ are violated, so the output is $3$. Constraints: For $25\%$ of the testdata: $1 \le g \le 50$, $1 \le x \le 50$, $y = 0$. For another $60\%$ of the testdata: $1 \le g \le 50$, $1 \le x \le 50$, $1 \le y \le 50$. For $100\%$ of the testdata: $1 \le g \le 10^5$, $1 \le x \le 10^5$, $1 \le y \le 10^5$. Translated by ChatGPT 5