2386: Good Groups

Memory Limit:128 MB Time Limit:10.000 S
Creator:
Submit:6 Solved:1

Description

A class has been divided into groups of three. This division into groups might violate two types of constraints: some students must work together in the same group, and some students must work in separate groups. 
Your job is to determine how many of the constraints are violated.
一个班级被分成了三人小组。这种分组可能违反两种约束:一些学生必须在同一个小组工作,而另一些学生必须在不同的小组工作。
你的任务是确定有多少约束被违反了。

Input

The first line will contain an integer X with X ≥ 0. The next X lines will each consist of two different names, separated by a single space. These two students must be in the same group. 
The next line will contain an integer Y with Y ≥ 0. The next Y lines will each consist of two different names, separated by a single space. These two students must not be in the same group. 
Among these X + Y lines representing constraints, each possible pair of students appears at most once. 
The next line will contain an integer G with G ≥ 1. The last G lines will each consist of three different names, separated by single spaces. These three students have been placed in the same group. 
Each name will consist of between 1 and 10 uppercase letters. No two students will have the same name and each name appearing in a constraint will appear in exactly one of the G groups.

第一行将包含一个整数 X,X ≥ 0。接下来的 X 行中,每行将包含两个不同的名字,之间用一个空格分隔。这两个学生必须在同一个小组。
下一行将包含一个整数 Y,Y ≥ 0。接下来的 Y 行中,每行将包含两个不同的名字,之间用一个空格分隔。这两个学生不能在同一个小组。
在这 X + Y 行代表约束的行中,每对可能的学生组合最多出现一次。
下一行将包含一个整数 G,G ≥ 1。最后的 G 行中,每行将包含三个不同的名字,之间用单个空格分隔。这三个学生已被安排在同一个小组。
每个名字将由 1 到 10 个大写字母组成。没有两个学生会有相同的名字,并且每个出现在约束中的名字将在 G 个小组中的一个中准确出现。

Output

Output an integer between 0 and X +Y which is the number of constraints that are violated.
输出一个在 0 到 X+Y 之间的整数,这个整数是被违反的约束数量。

Sample Input

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

Sample Output

3

HINT

The first constraint is that A and B must be in the same group. This is violated. 
The second constraint is that G and L must be in the same group. This is violated. 
The third constraint is that J and K must be in the same group. This is not violated. 
The fourth constraint is that D and F must not be in the same group. This is violated. 
The fifth constraint is that D and G must not be in the same group. This is not violated. 
Of the five constraints, three are violated.
第一个约束是 A 和 B 必须在同一个小组。这个被违反了。 
第二个约束是 G 和 L 必须在同一个小组。这个也被违反了。 
第三个约束是 J 和 K 必须在同一个小组。这个没有被违反。 
第四个约束是 D 和 F 不能在同一个小组。这个被违反了。 
第五个约束是 D 和 G 不能在同一个小组。这个没有被违反。
在这五个约束中,有三个被违反了

Source/Category