Try to find edges i -> j and j -> k having weight 0
for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( j == i ) : NEW_LINE INDENT continue NEW_LINE DEDENT if ( adj [ i ] [ j ] == '0' ) : NEW_LINE INDENT if ( len ( mp1 [ j ] ) ) : NEW_LINE INDENT k = mp1 [ j ] [ 0 ] NEW_LINE if ( k == i or k == j ) : NEW_LINE INDENT continue NEW_LINE DEDENT print ( " YES " ) NEW_LINE K -= 2 NEW_LINE K = k // 2 NEW_LINE DEDENT DEDENT DEDENT DEDENT