intread() { int x=0,f=1; char c=getchar(); while (!isdigit(c)) f=c=='-'?-1:1,c=getchar(); while (isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; }
voiddfs1(int u,int fat) { dep[u]=dep[fat]+1; fa[u]=fat; siz[u]=1; int i,v; for (i=head[u];i;i=edge[i].nxt) { v=edge[i].to; if (v==fat) continue; dfs1(v,u); siz[u]+=siz[v];//一开始漏写了这行导致找不出哪里错 if (siz[v]>siz[son[u]]) son[u]=v; } }
voiddfs2(int u,int tp) { top[u]=tp; id[u]=++cnt; key[cnt]=a[u]; if (!son[u]) return; dfs2(son[u],tp); int i,v; for (i=head[u];i;i=edge[i].nxt) { v=edge[i].to; if (v==fa[u]||v==son[u]) continue; dfs2(v,v); } }