If a pipe has no ending vertex but has starting vertex i . e is an outgoing pipe then we need to start DFS with this vertex .
for j in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( rd [ j ] == 0 and cd [ j ] ) : NEW_LINE INDENT ans = 1000000000 NEW_LINE w = dfs ( j ) NEW_LINE DEDENT DEDENT