union-find2 [Python] 백준 1976번 - 여행 가자(2) 문제백준 1976번최종 코드import sysinput = sys.stdin.readlinen = int(input())m = int(input())L = [i for i in range(n + 1)]def union(a, b): if L[a] != a: a = find(a) if L[b] != b: b = find(b) if a != b: L[b] = adef find(a): if L[a] == a: return a root = find(L[a]) L[a] = root return rootfor i in range(1, n + 1): temp = [0] + list(map(int, input().split()).. 2024. 5. 6. [Python] 백준 1043번 - 거짓말 문제백준 1043번최종 코드import sysinput = sys.stdin.readlinen, m = map(int, input().split())truth = list(map(int, input().split()))people = [i for i in range(n + 1)]parties = []def union(a, b): if people[a] != a: a = find(a) if people[b] != b: b = find(b) if a != b: people[b] = adef find(a): if people[a] == a: return a root = find(people[a]) people[a] = root .. 2024. 5. 6. 이전 1 다음