import java.io.*; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int n=Integer.parseInt(bu.readLine()); int i,c[]=new int[n],e[]=new int[n]; ArrayList g[]=new ArrayList[n]; for(i=0;i(); for(i=0;i g[],int c[],int n,int p) { for(int x:g[n]) if(x!=p) { dfs(g,c,x,n); c[n]+=c[x]; if(x g[],int c[],int e[],int n,int p) { for(int x:g[n]) if(x!=p) { e[x]=e[n]; e[x]+=c[n]-c[x]; if(n>x) e[x]--; else e[x]++; reroot(g,c,e,x,n); } } }