BFS function to find minimum distance
def bfs ( visit , dist , q ) : NEW_LINE INDENT global g NEW_LINE while ( len ( q ) > 0 ) : NEW_LINE INDENT temp = q . popleft ( ) NEW_LINE for i in g [ temp ] : NEW_LINE INDENT if ( visit [ i ] != 1 ) : NEW_LINE INDENT dist [ i ] = min ( dist [ i ] , dist [ temp ] + 1 ) NEW_LINE q . append ( i ) NEW_LINE visit [ i ] = 1 NEW_LINE DEDENT DEDENT DEDENT return dist NEW_LINE DEDENT