We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3d1f12b commit 4f0f64fCopy full SHA for 4f0f64f
1 file changed
live11/test116/문제1/박희경.py
@@ -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
21
22
+ while y not in x_roots:
23
+ y = tree[y]
24
25
+ print(y)
0 commit comments