hardy_9795's blog

By hardy_9795, history, 3 years ago, In English

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.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
3 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

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.

»
3 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

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.

»
3 years ago, # |
  Vote: I like it +9 Vote: I do not like it

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