i am sharing my code link here . i have used dfs approach to find connected components and storing them in a vector . i am failing 2 test cases !
I am getting WA
@JARVIS17 Consider test case:
10 7
0 2
1 8
1 4
2 8
2 6
3 5
6 9
3 sets {0,1,2,4,6,8,9} {3,5} {7}
So answer should be 23. But your code is giving 33.
In one of the graphs webinar of Prateek Bhaiya, he has discussed about a problem named “Journey to the Moon” which is similar to this problem. Refer that video and then try to solve this.
thanks bro . i got my mistake . i am implementing this question using disjoint set also . if i face any difficulty , i will ask again