### centinelprime420's blog

By centinelprime420, history, 6 weeks ago,

I am struggling from past week on this question, any suggestion or hint will be appreciated.

I have tree with n nodes with some stones tied on it. I want to make difference between any two adjacent node's stones as 1 or 0. I can do this adding any number of stones any number of times on any node in any order.

Idea is to minimize number of stones needed.

• +5

 » 6 weeks ago, # |   0 Auto comment: topic has been updated by centinelprime420 (previous revision, new revision, compare).
 » 6 weeks ago, # |   0 First, notice that you cannot remove stones. For that reason you cannot lower the maximum number of stones on any node. You would have to do something involving the node with max stones first, then the node with second to max and so on. Let's keep a heap/priority_queue with the biggest value at the top. Then consider a lee/bfs algorithm, but always take the source as the biggest value node. When moving to the neighbours you can change their values on the graph by adding at most node-1-neighbour. That gets you to node-1. If the value in the neighbour is node or node-1 then don't change that. When you change the value in the graph you will also need to update the key in the heap/p_q. The complexity should be O(NlogN) where N is the number of nodes.The example you gave would go like: Exampleheap: {(4, 6), (5, 5), (2, 4), (3, 2), (1, 1)}node=4, stones=6, heap: {(5, 5), (2, 4), (3, 2), (1, 1)}Update node (2, 4) to (2, 5), add=1heap: {(5, 5), (2, 5), (3, 2), (1, 1)}node=5, stones=5, heap: {(2, 5), (3, 2), (1, 1)}Update node (3, 2) to (3, 4), add=3heap: {(2, 5), (3, 4), (1, 1)}node=2, stones=5, heap: {(3, 4), (1, 1)}Do not update node (3, 4). Update node (1, 1) to (1, 4), add=6heap: {(3, 4), (1, 4)}node=3, stones=4, heap: {(1, 4)}No neighbour, no updatenode=1, stones=4heap: {}After doing the math I saw that the answer given is wrong in the text given.
•  » » 6 weeks ago, # ^ |   0 Yep, it seems that the text given does not present the correct solution to the stated problem.