Function which will check if there is a path between a and b by using BFS
bool checkPath ( char a , char b , map < char , vector < char > > & G ) { map < char , bool > visited ; deque < char > queue ; queue . push_back ( a ) ; visited [ a ] = true ; while ( ! queue . empty ( ) ) { int n = queue . front ( ) ; queue . pop_front ( ) ; if ( n == b ) return true ; for ( auto i : G [ n ] ) { if ( visited [ i ] == false ) { queue . push_back ( i ) ; visited [ i ] = true ; } } } return false ; }