Can you please help me on this, I commented my queryYour text to link here...
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
Can you please help me on this, I commented my queryYour text to link here...
Name |
---|
Say we have a tree as given. If we can find the maximum of the tree, it will have no bad neighbors and be a valid answer. Now let's consider their step — take the centroid of the tree and check it. If there is no bad neighbor we are done, but if there is any bad neighbor then we know that the node we selected cannot be a bad neighbor of the node they returned. That means that if we split the tree on the edge between the two, we get a smaller subtree which also must have a (local) maximum. That (local) maximum will be a valid answer.
I understand that far but I want to know why there will always be a local maxima.
There will always be a local maxima because out of the numbers in the tree there must be a single greatest or many tied for greatest. If there are ties then they are = to each other and therefore make no bad edges. All the other nodes are smaller than them. Therefore all of the largest numbers have no bad edges.
When we split the tree we don't guarantee that the subtree has the same largest elements, only that you can apply the same reasoning to the new tree.