### monsij's blog

By monsij, history, 12 months ago, ,

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!!

•
• -3
•

 » 12 months ago, # | ← Rev. 2 →   +5 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.
•  » » 12 months ago, # ^ |   +2 Thanks
•  » » » 12 months ago, # ^ |   0 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.
•  » » » » 12 months ago, # ^ |   0 Thanks dude!
•  » » » » » 12 months ago, # ^ |   -12 By the way can it manage n= 10^6?
•  » » » » » » 12 months ago, # ^ |   0 Nope, you might want to check single source shortest paths too.
•  » » » » » » » 12 months ago, # ^ |   0 Ok!