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 | 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 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.