Implementation of Floyd-Warshall and Bellman-Ford algorithms