Hey @raghav007, you can remove the default code and write your own full code or they have given the function just write your code there on. See you don’t need to calculate the ncr or something like that. Just check if the node is not visited take the dfs and push its size into a vector. After pushing all such sizes you just need to calculate sum of all products at a time.
For that we can use a formula answer = ((sum)^2 - arr[0]^2 - arr[1]^2 … - arr[n-1]^2)
I hope it will be clear to you, else if there will be any confusion, pls let me know.
Thanks 