Code issue , , , , , , , ,, , , , , , , , , , , , , , , ,

i tried lot of times but i didn’t reach at solution …
Here is my approach
at first i stored all component of graph with size then calculate them one by one
is it right approach???

@Nitin-Mishra-2380486738834604
yeah calculate connected components in given graph with their size(i.e number of nodes in connected coponent) and then simple pnc.

hint use union find
numbers of ways will be-> ways to pick one node from first component X ways to pick 2nd node from 2nd component

=> n1 * n2

now u need to extend the same logic when u have more than 2 connected components.

check reference code if u need