monsij's blog

By monsij, history, 7 years ago, In English

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

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
Rev. 2   Vote: I like it +5 Vote: I do not like it

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.