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.
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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.
Название |
---|
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.