Only one testcase is passing

hello @gargshivam2001

whats ur approach?

here, I am using DFS and finding the no. of vertices in each component and thus, finding the no ways from one city to another.

@aman212yadav please have a look on my approach

…

how?whats the logic?
…
…
,

@aman212yadav here, I am finding the cities in each component by using count variable and pushing the same in component vector and now component vector contains the no. cities in each component and after the i am finding the ways such that the 2 cities doesn’t belong to same component.

this is what i want to know.

anyway.

if N is total number of cities and x is the number of cities in a component then if u pick one city from x and another city from N-x then they will not belong to one component.
and ways of doing this will be X * (N-X)

do this for all component and then print ans/2

diving by 2 becuase each pair will be counted twice

@aman212yadav sir I have already tried to do that but if there is any only one city in the component, then acc. to my code it will not be added in component vector so finding the ways from that city will not be added in the ans, so dividing by 2 will give wrong ans.

@gargshivam2001

no u have to repeat it for all components.
it is working.

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.