import numpy as np class sol(object): def __init__(self, N, tree): self.N = N self.tree = tree self.dp0 = np.array([0] * N, dtype=int) self.dp1 = np.array([0] * N, dtype=int) self.visit_cnt = [0] * N self.top_root = np.array([True] * N, dtype=bool) for child in tree: self.top_root[child] = False self.top_root = np.where(self.top_root == True)[0] def dns(self, cur): h = [] h.append(cur) while len(h) > 0: v = h.pop() self.visit_cnt[v] += 1 if len(self.tree[v]) == 0: self.dp0[v] = 1 self.dp1[v] = 0 elif self.visit_cnt[v] -1 < len(self.tree[v]): h.append(v) h.append(self.tree[v][self.visit_cnt[v] -1]) else: self.dp1[v] = sum(max(t) for t in zip(self.dp0[self.tree[v]], self.dp1[self.tree[v]])) self.dp0[v] = 1 + sum([max(t[0] -1, t[1]) for t in zip(self.dp0[self.tree[v]], self.dp1[self.tree[v]])]) return def ans(self): for v in self.top_root: self.dns(v) return sum([max(t) for t in zip(self.dp0[self.top_root], self.dp1[self.top_root])]) N=int(input()) tree = [[] for i in range(N)] for i in range(N -1): e = list(map(int, input().split())) tree[e[0] -1].append(e[1] -1) print(sol(N, tree).ans())