Lakshi4h's blog

By Lakshi4h, history, 3 years ago, In English

This is my code to solve 229B - Planets

my code

107892710

But it get TLE on test 66. It's just a dijsktra with a simple modification. I can't figure out a way to make this any more faster.

Here's another code i found from top of the standings. It's almost the same as mine but passes in a very small time. I've been comparing two codes but have no idea for a reason for TLE.

2276080

Can someone help me figure out the problem?

Thank you.

  • Vote: I like it
  • +2
  • Vote: I do not like it

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

Your solution is O(M * log(n) * log(q)), but AC solution is O(M * log(n)), try to cut excess logarithm

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Oh i can move the small while loop outside of the for loop because i'm repeating the same thing. Couldn't see it even when i was comparing two codes ;-;

    Thank you for your help

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I also read your codes, and I am not quite sure but I think it is this line

      'while(trav[v].find(t)!=trav[v].end())t++;'

      that costs too much time. Perhaps you could move it outside the loop

      'for(auto e : adjList[v])'

      since the result keeps the same whatever element 'e' is.