I have a tree, $T$, with $n$ nodes. My goal is to assign a non-zero weight to each node such that the following condition is met:
Upon removing any arbitrary node, the total weight of nodes in each resulting connected component should be equal.
Consider the following tree as an example:
1 -- 2 -- -3 -- 4
|
1
In this tree, if we remove any node, the total weight of the nodes in each of the resulting connected components is equal. For instance, if we remove the node with weight $-3$, we end up with two connected components, each with a total weight of $4$.
I am seeking an algorithm that can find these weights in polynomial time.
My initial approach was to assign arbitrary values to the nodes. Then, for each node, I would check if the condition is satisfied when that node is removed. This check can be performed in $O(n)$ time using graph traversal algorithms like BFS or DFS. However, I am unsure how to adjust the tree because correcting the condition for one node seems to disrupt the condition for almost all other nodes.
Any suggestions or insights would be greatly appreciated.