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

Автор ameyanator, история, 6 лет назад, По-английски

I've been trying to solve this question, but I keep on getting a TLE. At first I had an O(V*(E+V)) approach (link). Then I optimized my code so that I store the results of other nodes while calculating the answer of some node. (link). I'm still getting an TLE.

Can anyone please suggest another optimization/approach for this question so that I can get an AC?

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

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

Auto comment: topic has been updated by ameyanator (previous revision, new revision, compare).

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

Urm anyone please?!

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Either adding cout.tie(0) or using scanf/printfmay work :).

UPD: No, it's not any of them, I tried.

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

Your solution's complexity seems to be O(V3).

in worst case

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

Update Solved the question. All it required was an optimization — Inside our bfs we need to consider only those nodes that the current node stems out to. We can preprocess this or use adjacency list representation.