Skip to content

Commit 4f0f64f

Browse files
committed
116차 1번 문제풀이
1 parent 3d1f12b commit 4f0f64f

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
from collections import *
3+
4+
input = sys.stdin.readline
5+
6+
t = int(input())
7+
8+
for _ in range(t):
9+
n = int(input())
10+
tree = defaultdict(list)
11+
for _ in range(n-1):
12+
a, b = map(int, input().split())
13+
tree[b] = a
14+
x, y = map(int, input().split())
15+
16+
x_roots = set()
17+
while x in tree:
18+
x_roots.add(x)
19+
x = tree[x]
20+
x_roots.add(x)
21+
22+
while y not in x_roots:
23+
y = tree[y]
24+
25+
print(y)

0 commit comments

Comments
 (0)