mahmoud13's blog

By mahmoud13, history, 8 months ago, In English

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?

  • Vote: I like it
  • -1
  • Vote: I do not like it

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Infinity DFS ((

  • »
    »
    8 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      8 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

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

      • »
        »
        »
        »
        8 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

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

»
8 months ago, # |
  Vote: I like it +3 Vote: I do not like it

corrected version

Spoiler
  • »
    »
    8 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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?