Find connected components of the complementary graph


You are given an undirected graph with $ N$ vertices and $ M$ edges.

Find all the connected components in the compliment of the given graph optimally (in $ O(M)$ or $ O(MlogN)$ ).

//input 4 4 //n,m 1 2  1 3 4 2 4 3  //output 2 //no of connected components 2 1 4  2 2 3  

Source

Editorial (I didn’t get it)