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?
Auto comment: topic has been updated by mahmoud13 (previous revision, new revision, compare).
Infinity DFS ((
Can you explain more how is it infinity DFS? :(
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. ))
But I am updating the minCost in the function, so why it is not working?
I mean if the mincost is -1 then it is not visited, else, it will be updated.
corrected version
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 :(
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.
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?
yes, don't make copy on every call, use call by ref.
Thank you very much!! :)