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 ( var i = 0 ; i < E ; i ++ ) { var x = graph [ i ] [ 0 ] ; var y = graph [ i ] [ 1 ] ; var weight = graph [ i ] [ 2 ] ; if ( ( dis [ x ] != 1000000000 ) && ( dis [ x ] + weight < dis [ y ] ) ) document . write ( " " + " " ) ; } document . write ( " " ) ; for ( var i = 0 ; i < V ; i ++ ) document . write ( i + " " + dis [ i ] + " " ) ; }