PAIRING(Graph Challenge)

What is the most efficient way of doing this problem?

Find connected components.
Any vertex from one set of C.C will definitely not have a path to other vertex of another C.C

I did the same thing and it got accepted but is there some other approach to this question?

Well done then! I This is most efficient i think!