A recuesive function to perform DFS with vertex i as source
void DFSvisit ( int i , int * mat [ ] , bool visited [ ] , vector < int > & sol , int n ) { visited [ i ] = true ; sol . push_back ( i ) ; for ( int j = 0 ; j < n ; j ++ ) if ( mat [ i ] [ j ] && ! visited [ j ] ) DFSvisit ( j , mat , visited , sol , n ) ; }