Can you please help me on this, I commented my queryYour text to link here...
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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.