import sys input = sys.stdin.readline N = int(input()) tree = [[-1 for _ in range(2)] for _ in range(N+1)] for i in range(1,N+1): left_ndoe,right_node = map(int,input().split()) tree[i][0] = left_ndoe tree[i][1] = right_node K = int(input()) cu_node = 1 while K >=0: left_or_right = K%2 if tree[cu_node][0] != -1 and tree[cu_node][1] != -1: if left_or_right: cu_node = tree[cu_node][0] else: cu_node = tree[cu_node][1] K = K//2 + left_or_right else: if tree[cu_node][0] == -1 and tree[cu_node][1] == -1: break elif tree[cu_node][1] == -1: cu_node = tree[cu_node][0] else: cu_node = tree[cu_node][1] print(cu_node)
'알고리즘 > 백준_복기_미완료' 카테고리의 다른 글
[BOJ/백준] 1717 집합의 표현 (0) | 2021.05.05 |
---|---|
[BOJ/백준] 14595 동방 프로젝트(Large) (0) | 2021.05.05 |
[BOJ/백준] 14476 최대공약수 하나 빼기 (0) | 2021.05.05 |
[BOJ/백준] 13974 파일 합치기 2 (0) | 2021.05.05 |
[BOJ/백준] 13913 숨바꼭질 4 (0) | 2021.05.05 |