2022 J4 - Good Groups

Normalimplementation

1 Solution Available

Solution 1

PYTHON
1# By Oscar Zhou, Abbey Park High School
2# This solution still requires commented explanations. Please feel free to add them!
3
4# https://dmoj.ca/problem/ccc22s2
5
6import sys
7input = sys.stdin.readline
8
9x = [input().strip().split() for i in range(int(input()))]
10y = [input().strip().split() for i in range(int(input()))]
11groups = {}
12cnt = 0
13for i in range(int(input())):
14    a, b, c = input().strip().split()
15    groups[a], groups[b], groups[c] = cnt, cnt, cnt
16    cnt += 1
17ans = 0
18for item in x:
19    if groups[item[0]] != groups[item[1]]: ans += 1
20for item in y:
21    if groups[item[0]] == groups[item[1]]: ans += 1
22print(ans)

Test Cases

Select a test case to view input and output