inlinevoiddfs(int x, int yhm_fa) { int i, y; siz[x] = 1; for (i = head[x]; i; i = nex[i]) { y = ver[i]; if (y == yhm_fa) continue; dfs(y, x); siz[x] += siz[y]; dis[x] += dis[y] + siz[y]; } return; }
inlinevoidfuck(int x, int yhm_fa) { int i, y; for (i = head[x]; i; i = nex[i]) { y = ver[i]; if (y == yhm_fa) continue; f[y] = f[x] - siz[y] + n - siz[y]; fuck(y, x); } }
signedmain() { int i, x, y, res(inf); n = read(); for (i = 1; i < n; ++ i) { x = read(), y = read(); add_edge(x, y), add_edge(y, x); } dfs(1, 0); f[1] = dis[1]; fuck(1, 0); for (i = 1; i <= n; ++ i) res = min(res, f[i]); put(res); return0; }