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

Автор mahmoud13, история, 8 месяцев назад, По-английски

I was trying to solve this problem 1851E - Nastya and Potions, and I submitted this code 233066590. It's the same logic of the editorial, that's what I think, but it's getting TLE. Can anyone tell me what is the wrong with my code so it's getting this TLE?

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

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

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

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

Infinity DFS ((

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

    Can you explain more how is it infinity DFS? :(

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

      Your minCost is not working. So you have to mark a node as a visited node, then you have to check the adjacent node where is visited or not. ))

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

        But I am updating the minCost in the function, so why it is not working?

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

        I mean if the mincost is -1 then it is not visited, else, it will be updated.

»
8 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

corrected version

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

    I'm sorry, but can you tell me what have you changed? I read the code you sent and I didn't found any difference, maybe I didn't read your code correctly :(

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

    Ok, I found the & in the dfs function, but why it is getting TLE without it? I mean, I'm not changing the vector v in the dfs.

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

    Is it that if I copy the vector v multiple time for the dfs function, it takes more time making the time complexity of the code larger?