implemented Bellman-Ford algorithm