-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11725.py
More file actions
39 lines (26 loc) · 783 Bytes
/
11725.py
File metadata and controls
39 lines (26 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 트리를 직접 구현했었음
import sys
n = int(sys.stdin.readline())
class Node:
def __init__(self, data):
self.data = data
self.parent = None
self.child = []
def makeTree(node, arr, res):
for i in range(len(arr[node.data])):
if arr[node.data][i]:
arr[i][node.data] = arr[node.data][i] = 0
child = Node(i)
node.child.append(child)
child.parent = node
res[child.data] = node.data
makeTree(child, arr, res)
arr = [[0] * (n+1) for i in range(n+1)]
for i in range(n-1):
v1, v2 = map(int, input().split())
arr[v1][v2] = arr[v2][v1] = 1
res = [0 for i in range(n+1)]
node = Node(1)
makeTree(node, arr, res)
for i in range(2, n+1):
print(res[i])