We cannot travel through edge that doesn 't exist
if ( dis [ i ] [ k ] == INF or dis [ k ] [ j ] == INF ) : NEW_LINE INDENT continue NEW_LINE DEDENT if ( dis [ i ] [ j ] > dis [ i ] [ k ] + dis [ k ] [ j ] ) : NEW_LINE INDENT dis [ i ] [ j ] = dis [ i ] [ k ] + dis [ k ] [ j ] NEW_LINE Next [ i ] [ j ] = Next [ i ] [ k ] NEW_LINE DEDENT