from sys import setrecursionlimit setrecursionlimit(10**6) from heapq import heappop,heappush def dfs(pos, pre): global G, Vec for nxt in G[pos]: if nxt == pre: continue P = dfs(nxt, pos) heappush(Vec[pos], -P) M = len(Vec[pos]) idx = pos for nxt in G[pos]: if nxt == pre: continue if len(Vec[nxt]) > M: M = len(Vec[nxt]) idx = nxt if idx != pos: while Vec[pos]: heappush(Vec[idx], heappop(Vec[pos])) for nxt in G[pos]: if nxt == pre: continue if nxt == idx: continue while Vec[nxt]: heappush(Vec[pos], heappop(Vec[nxt])) Vec[pos] = Vec[idx] 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))