lamda_cdm's blog

By lamda_cdm, history, 21 month(s) ago, In English

I was trying this problem. Tried a greedy solution , where I number the nodes starting from the lower level . And take every leaf node one by one . Someway it's failing . I tried making counter test cases but couldn't find a case where my solution failed. Here's my link 196466553 to the submission . Problem 1740E - Подвешенные сердца

Thanks in advance

  • Vote: I like it
  • +4
  • Vote: I do not like it

»
21 month(s) ago, # |
  Vote: I like it +7 Vote: I do not like it

counter test case :

Input: 
5
1 2 2 4

expected output : 4
your output : 3

values of vertices = [5 4 2 3 1]

I hope you can figure out, if not let me know.

  • »
    »
    21 month(s) ago, # ^ |
    Rev. 2   Vote: I like it +6 Vote: I do not like it

    Hey thanks sktime I just solved the problem turns out we can further optimise my logic by starting out giving numbers to deeper nodes rather than starting from a random leaf node . So what i did was to sort the adjajency list by the depths of the nodes. It got AC . thanks once again. here's my submission if you wanna look into it 196546094. I hope we can cooperate in future .