728x90
SMALL
n = int(input())
tree = {}
# 전위 순회 preorder : root -> left -> right
# 중위 순회 inorder : left -> root -> right
# 후위 순회 postorder : left -> right -> root
for _ in range(n):
root,left,right = map(str,input().split())
tree[root] = [left,right]
def preorder(root):
if root!='.':
print(root,end='')
preorder(tree[root][0])
preorder(tree[root][1])
def inorder(root):
if root!='.':
inorder(tree[root][0])
print(root,end='')
inorder(tree[root][1])
def postorder(root):
if root!='.':
postorder(tree[root][0])
postorder(tree[root][1])
print(root,end='')
preorder('A')
print()
inorder('A')
print()
postorder('A')
728x90
LIST
'취준시절 > 백준' 카테고리의 다른 글
[백준 2231] Python - 분해합 (0) | 2021.08.26 |
---|---|
[백준 1780] Python - 종이의 개수 (0) | 2021.08.25 |
[백준 2630] Python - 색종이 만들기 (0) | 2021.08.25 |
[백준 1932] Python - 정수 삼각형 (0) | 2021.08.24 |
[백준 12015번] Python - 가장 긴 증가하는 부분 수열 2 (0) | 2021.08.24 |