Data Structures & AlgorithmsVery hardICPC regional · graph theory

Problem: Which statement about Floyd-Warshall on a graph with V = 400 vertices and no negative cycles is correct?

  1. A. About 1.6 * 10^5 relaxations, so it must be replaced by Dijkstra from every vertex
  2. B. It needs O(V!) time and is infeasible for V = 400
  3. C. It cannot handle negative weights at all, even without negative cycles
  4. D. About 6.4 * 10^7 relaxations, which runs comfortably in C++; negative edges are allowed

Correct answer: D. About 6.4 * 10^7 relaxations, which runs comfortably in C++; negative edges are allowed

The triple loop does V^3 = 6.4 * 10^7 relaxations for V = 400, which is fine in C++. Negative edges are allowed as long as there is no negative cycle.

More Coding Interview Problems questions

Exams that ask this topic