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

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

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 - Hanging Hearts

Thanks in advance

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

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

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.

  • »
    »
    15 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

    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 .