Please resolve the error

debug my code. https://ide.codingblocks.com/s/268878

Hey Pulkit, its a classical components question.
Find out connected cities for a given city and lets say that it is connected with total x cities (including itself), then what is the contribution of this city?
Well you can pair this city with every N-x cities!, now what’s the contribution for this group of x cities? it is x(N-x)
so just get connected components for each unvisited city and add x(N-x) to your answer. Number of connected components can be easily found by DFS/BFS.

i am using dsu to solve the question. its giving internal error. debug it. https://ide.codingblocks.com/s/268878

Initialize par[i] with i instead of -1.
Also how can you calculate answer using superparent?

not able to pass all the test cases. what conditions i am missing. https://ide.codingblocks.com/s/268878

this is my second approach(using dfs).still not able to pass test cases.please debug it . https://ide.codingblocks.com/s/269857

Answer is sz/2 and not sz/components
also take type as long long to avoid overflow.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

my code has been accepted for all the test cases. But the question is not getting green tick. please look into this.

for this you can write to [email protected]