Good Groups
InterviewTime limit1sMemory limit1024 MB
Given same-group and separate-group constraints plus the actual groups of three, count how many constraints the grouping violates.
- Level
Medium4 of 10
- Topics
- Hash map, Implementation, String, Array
- Solved
- No attempts yet
Problem
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.
Determine how many of the constraints are violated.
Input
The first line contains an integer (). The next lines each consist of two different names, separated by a single space. These two students must be in the same group.
The next line contains an integer (). The next lines each consist of two different names, separated by a single space. These two students must not be in the same group.
Among these lines representing constraints, each possible pair of students appears at most once.
The next line contains an integer (). The last lines each consist of three different names, separated by single spaces. These three students have been placed in the same group.
Each name consists of between 1 and 10 uppercase letters. No two students have the same name, and each name appearing in a constraint appears in exactly one of the groups.
Output
Output an integer between and , the number of constraints that are violated.