import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) N=int(input()) edge = [[] for _ in range(N)] XY=[list(map(int,input().split())) for _ in range(N-1)] for x,y in XY: x,y=x-1,y-1 edge[x].append(y) edge[y].append(x) visit = [0]*N dnode = [] from heapq import * def dfs(v=0): visit[v]=1 n_tree = [] del_lst = [] for to in edge[v]: if visit[to]:continue n,lst = dfs(to) n_tree.append(n) del_lst.extend(lst) if len(n_tree)==0: return 1,[] if len(n_tree)==1: if del_lst: # heapify(del_lst) n = -heappop(del_lst) else: n=0 return n+n_tree[0]+1,del_lst if len(n_tree)<=2: return sum(n_tree)+1,del_lst # n_tree.sort(reverse=True) # 重い mx1,mx2=0,0 for n in n_tree: if mx1