package Chapter3;
import java.io.*; import java.util.Arrays;
public class P846 { private static final int N = 100010, M = N * 2; private static int[] h = new int[N], e = new int[M], ne = new int[M]; private static boolean[] st = new boolean[N]; private static int ans = N, idx, n; private static void add(int a, int b){ e[idx] = b; ne[idx] = h[a]; h[a] = idx++; } private static int dfs(int u){ st[u] = true; int sum = 1; int res = 0; for(int i=h[u];i!=-1;i=ne[i]){ int j = e[i]; if(!st[j]){ int s = dfs(j); res = Math.max(res, s); sum += s; } } res = Math.max(res, n-sum); ans = Math.min(res, ans); return sum; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); Arrays.fill(h, -1); for(int i=0;i<n-1;i++){ String[] str = br.readLine().split(" "); int a = Integer.parseInt(str[0]); int b = Integer.parseInt(str[1]); add(a,b); add(b,a); } dfs(1); System.out.println(ans); } }
|