Counts number of vertices connected in a component containing x . Stores the count in k .
static void dfs ( Vector < Integer > graph [ ] , boolean visited [ ] , int x ) { for ( int i = 0 ; i < graph [ x ] . size ( ) ; i ++ ) { if ( ! visited [ graph [ x ] . get ( i ) ] ) {