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
counter test case :
I hope you can figure out, if not let me know.
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 .
Glad that you got AC.