from sys import setrecursionlimit setrecursionlimit(10**6) from heapq import heappop,heappush def dfs(pos, pre): global Vec for nxt in G[pos]: if nxt == pre: continue P = dfs(nxt, pos) heappush(Vec[pos], -P) for nxt in G[pos]: if nxt == pre: continue while Vec[nxt]: heappush(Vec[pos], heappop(Vec[nxt])) ret = 1 if len(Vec[pos]) <= 2: while Vec[pos]: ret += -heappop(Vec[pos]) else: for _ in range(2): ret += -heappop(Vec[pos]) return ret N = int(input()) G = [[] for _ in range(N)] for _ in range(N-1): x,y = map(int,input().split()) x -= 1 y -= 1 G[x].append(y) G[y].append(x) Vec = [[] for _ in range(N)] print(dfs(0, -1))