Hello Codeforces!,
We already have a algorithm to find all pairs shortest path in a weighted graph.This solution depends on dynamic programming ideas and hence utilizes one/two 2-D matrices.But I wonder what would be the approach if the number of vertices increased to say 10^4 or maybe as large as 10^6. Thanks in Advance!!
Well, as you are asking for O(V2) paths there can't be anything better than O(V2) — so you should probably forget about the V = 106 case.
Anyway, for sparse graphs, you can run Dijkstra's algorithm for each vertex and obtain a O(VE + V2logV) algorithm known as the Johnson's algorithm.
Thanks
Erik Demaine explains this concept really well, MIT OCW 6.046J DP : All-pairs shortest paths https://www.youtube.com/watch?v=NzgFUwOaoIw Johnson's algorithm is at around 58 min.
Thanks dude!
By the way can it manage n= 10^6?
Nope, you might want to check single source shortest paths too.