hello codeforces
can any one please tell me how to solve this problem link ,I tried several methods and none of them worked , I also read the tutorial for this problem but it was not clear for me :(
thanks
# | User | Rating |
---|---|---|
1 | ecnerwala | 3649 |
2 | Benq | 3581 |
3 | orzdevinwang | 3570 |
4 | Geothermal | 3569 |
4 | cnnfls_csy | 3569 |
6 | tourist | 3565 |
7 | maroonrk | 3531 |
8 | Radewoosh | 3521 |
9 | Um_nik | 3482 |
10 | jiangly | 3468 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 162 |
4 | TheScrasse | 159 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 151 |
8 | SecondThread | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
hello codeforces
can any one please tell me how to solve this problem link ,I tried several methods and none of them worked , I also read the tutorial for this problem but it was not clear for me :(
thanks
Name |
---|
We can prove that if a candidate is selected, no broken roads will be below his city in the tree. If there were, the candidate directly below that broken road would need to be selected, covering both the corresponding broken road and our initially selected candidate's broken road, making our initial candidate unneeded. This is a contradiction, as we want as few candidates as possible.
Therefore, all we have to do is DFS down the tree and mark down what candidate was last seen in each branch and the candidates that were replaced by another candidate lower than him. The answer is just the candidates that are in the last seen branch and not in the replaced branch.
Note that if a candidate is below another one, the upper candidate cannot possibly be in the answer, as if there were another branch that didn't have a replacing candidate, no candidate would be needed for this branch anyways.
18728585
Thanks a lot everyone :D