Relax all edges | V | - 1 times . A simple shortest path from src to any other vertex can have at - most | V | - 1 edges
for i in range ( V - 1 ) : NEW_LINE INDENT for j in range ( E ) : NEW_LINE INDENT if dis [ graph [ j ] [ 0 ] ] + graph [ j ] [ 2 ] < dis [ graph [ j ] [ 1 ] ] : NEW_LINE INDENT dis [ graph [ j ] [ 1 ] ] = dis [ graph [ j ] [ 0 ] ] + graph [ j ] [ 2 ] NEW_LINE DEDENT DEDENT DEDENT