check for negative - weight cycles . The above step guarantees shortest distances if graph doesn 't contain  negative weight cycle. If we get a  shorter path, then there is a cycle.
for i in range ( E ) : NEW_LINE INDENT x = graph [ i ] [ 0 ] NEW_LINE y = graph [ i ] [ 1 ] NEW_LINE weight = graph [ i ] [ 2 ] NEW_LINE if dis [ x ] != maxsize and dis [ x ] + weight < dis [ y ] : NEW_LINE INDENT print ( " Graph ▁ contains ▁ negative ▁ weight ▁ cycle " ) NEW_LINE DEDENT DEDENT print ( " Vertex ▁ Distance ▁ from ▁ Source " ) NEW_LINE for i in range ( V ) : NEW_LINE INDENT print ( " % d TABSYMBOL TABSYMBOL % d " % ( i , dis [ i ] ) ) NEW_LINE DEDENT