Please read the new rule regarding the restriction on the use of AI tools. ×

I cannot find the bud in my code.

Revision en2, by shubhsy, 2018-12-29 15:45:57

I am trying to solve a problem, "Kefa and Park", https://codeforces.me/problemset/problem/580/C Here is the code I wrote and it does not give right answer for test case 12. Please, help me out. https://codeforces.me/contest/580/submission/47677278

My code builds a tree as per the question. After I build the tree, I do perform DFS. I have a stack in which I first put the first element (Root). Now, for every iteration for as long as there is an element in the stack, I check if its parent has a non zero value of number of cats in the path and if it has, I add the number of cats at that node to the upper number and if it does not, then, I switch it to the number of cats at that node. Now, if I reach the leaf and the number of consecutive cats in that path is less than or equal to the required number, I increase the number of valid paths by one.

Tags #c++, #bug, #trees, #dfs and similar

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English shubhsy 2018-12-29 15:45:57 630
en1 English shubhsy 2018-12-29 13:02:51 277 Initial revision (published)