Блог пользователя decrypt_me

Автор decrypt_me, история, 3 года назад, По-английски

Need Help! IN CSES Graph Series in Shortest Route 2 problem it is accepting solution of floyd warshall algorithm while O(n*2logn) not (using dijkastra Priority queue).

#

I want to know , when It is benificial to use floyd warshall algorithm and when not ?

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

If $$$O(n^3)$$$ is allowed then it is very short to code floyd warshall. Also, floyd warshall works with negative edges too.

You can check this problem, which uses the idea used in floyd warshall.

Hint
»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Your dijkstra code's complexity would be O(n*m*logn + q) rather than O(n^2*logn), so it will give TLE for the given constraints.