Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор The_Royalty, 10 лет назад, По-английски

Hello, I've been trying to solve this problem Jobbery but my code gets TLE on test 50.

Could someone help me to improve my algorithm? I think it's O(M+N) because I'm using Tarjan's algorithm

My code

Thanks

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

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

Nobody?

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

What you have written does not look like a linear algorithm. To understand what is wrong with it, please explain as clearly as you can (at least to yourself) what the lines 63 – 71 do and — specifically — what purpose the variable S serves.

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

    Isn't it just a stack, that will have at most n elements pushed and hence at most n elements popped?

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

    It's an implementation of Tarjan's algorithm taken from Competitive Programming 3 book.

    I will comment my codes for future questions. Thanks

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

stupid site -_-, I'm still waiting for some judge ID to submit the problem !!

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

Oh, but it passes :). Just change cin,cout to scanf,printf and send to Visual C++ 2010 B-). For some reason other combinations don't work.