Since , we made a graph with contacts as nodes with fields as links . two nodes are linked if they represent the same person . so , total number of connected components and nodes in each component will be our answer .
for ( int i = 0 ; i < n ; i ++ ) { if ( ! visited [ i ] ) { DFSvisit ( i , mat , visited , sol , n ) ;