from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc N = int(input()) G = [[] for _ in range(N)] for _ in range(N-1): a, b = map(int, input().split()) G[a-1].append(b-1) G[b-1].append(a-1) INF = 10**18 @bootstrap def dfs(n, pre, depth, flag): MIN = INF MAX = -INF for v in G[n]: if v != pre: turn = yield dfs(v, n, depth+1, flag) MIN = min(MIN, turn) MAX = max(MAX, turn) if MIN != INF: if (depth+flag)%2 == 0: yield MAX+1 else: yield MIN+1 else: yield 0 print(dfs(0, -1, 0, False)) print(dfs(0, -1, 0, True))