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 i in range ( n ) : NEW_LINE INDENT if ( not visited [ i ] ) : NEW_LINE INDENT DFSvisit ( i , mat , visited , sol , n ) NEW_LINE DEDENT DEDENT