Function to count distance
def bfs ( src ) : NEW_LINE INDENT global vis NEW_LINE global dis NEW_LINE q = [ ] NEW_LINE q . append ( src ) NEW_LINE vis [ src ] = 1 NEW_LINE dis [ src ] = 0 NEW_LINE while ( len ( q ) != 0 ) : NEW_LINE INDENT curr = q [ 0 ] NEW_LINE q . pop ( 0 ) NEW_LINE for x in lis [ curr ] : NEW_LINE DEDENT DEDENT