백준 11725- 트리의 부모 찾기
·
Algorithm/백준
bfs로 풀어주었다. from collections import deque import sys input = sys.stdin.readline N = int(input()) G = [[] for i in range(N+1)] for _ in range(N-1): a, b = map(int, input().split()) G[a].append(b) G[b].append(a) q=deque() q.append(1) ancestor = {} checked = [0] * (N+1) while q: parent = q.popleft() for i in G[parent]: if not checked[i]: ancestor[i] = parent q.append(i) checked[i] = 1 for i in rang..