题意: 思路: num[a[u]]表示存在a[u]这个颜色且终点在u子树中的链长总和 ans[i]表示以当前的u为根,前面的子树对i的贡献之和 ..]of longint; size,f,ans,sun,num,a,flag,vis,b,c:..]of longint; n,m,sum,root,i,tot,now,x,y:longint; procedure add(a,b:longint); begin inc(tot); next[tot]:=head[a]; vet[tot]:=b; h…