Can someone help me in understanding the solution for this problem. I am not getting any idea about what the editorial says. Please help. Thank you.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | 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 | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Can someone help me in understanding the solution for this problem. I am not getting any idea about what the editorial says. Please help. Thank you.
Name |
---|
We have to assign small values to the nodes having the least number of edges. Sort the given array and iterate from first and every time assign the current value to the edge with the minimum number of edges and remove that node from the graph. Since it is a tree, in every move you can just remove a leaf.
Understood. Thank you for helping.
I have a slightly different solution. First, sort all the $$$c_1, c_2, c_3, ..., c_n$$$ integers in non-increasing order: $$$c_1 \geq c_2 \geq c_3 \geq ... \geq c_n$$$. Then, the maximum possible score is $$$c_2+c_3+...+c_n$$$. Here is how to achieve it: $$$\newline$$$ Root the tree somewhere (say, the vertex $$$1$$$). Traverse the tree by DFS. Just when you're about to leave a vertex, assign the smallest unused integer $$$c_i$$$ to it. After finishing, vertices with higher depth have smaller values: $$$depth_{parent_v} < depth_v$$$ and $$$value_{parent_v} \geq value_v$$$. Each edge takes the value of an endpoint with higher depth. $$$\newline$$$ Refer to this code, if you didn't understand.
This is such a simple solution. Thank you so much.
sort in Descending order and root the tree at vertex 1 and find level order traversal of tree and assign value according to level order traversal. https://atcoder.jp/contests/m-solutions2019/submissions/24095526
Got it. Thanks for helping.