import numpy as np class sol(object): def __init__(self, N, tree): self.N = N self.tree = tree self.dp = np.zeros([N,2], dtype=int) self.visit = [False] * N self.parent = np.array([-1] * N, dtype=int) def dns(self, cur): h = [] h.append(cur) while len(h) > 0: v = h.pop() if len(self.tree[v]) == 1 and self.parent[v] == self.tree[v][0]: self.dp[v,1] = 0 self.dp[v,0] = 1 elif self.visit[v] == False: h.append(v) for child in self.tree[v]: if child != self.parent[v]: h.append(child) self.parent[child] = v else: t_dp = self.dp[self.tree[v]] self.dp[v, 1] = np.sum(np.max(t_dp, axis=1)) t_dp[:,0] -= 1 self.dp[v, 0] = 1 + np.sum(np.max(t_dp, axis=1)) self.visit[v] = True return def ans(self): self.dns(0) return max(self.dp[0,0],self.dp[0,1]) def main(): N=int(input()) tree = [[] for i in range(N)] for _ in range(N -1): e = list(map(int, input().split())) tree[e[0] -1].append(e[1] -1) tree[e[1] -1].append(e[0] -1) print(sol(N, tree).ans()) line_prof = False if line_prof: from line_profiler import LineProfiler profiler = LineProfiler() profiler.add_function(sol.dns) profiler.runcall(main) profiler.print_stats() else: main()