If we find a connection to the sink node , then there is no point in BFS anymore We just have to set its parent and can return true
if ind == t : NEW_LINE INDENT visited [ ind ] = True NEW_LINE return True NEW_LINE DEDENT queue . append ( ind ) NEW_LINE visited [ ind ] = True NEW_LINE parent [ ind ] = u NEW_LINE