can anyone help me how to solve this what i can think of is from (u,v) count of x can be used i.e if count of x=k then k*(k-1)/2 will be added to final query answer and hence we need to find count of 0 ,1,2,3,4…1e5 and then use the formula of ans+=count(x)(count(x)-1)/2 now i can think of finding count of each type using persistent segment tree at each node to store count of each type from root to every node then using count array from (u,v)= count array(root,u)+count array(root,v)-2count array(root,lca)+val[lca] but this does not reduce the complexity how to approach next please give a suggestion regarding this.