A tree with N nodes and N-1 Bidirectional edges, and given an integer S.
Now, you have to assign the weights to the edges of this tree such that:
1. the sum of the weights of all the edges is equal to S
2. for every possible diameter of the tree, the maximum weight over all the edges covered by its paths is the minimum possible.
Output this minimum possible edge weight.
The diameter of a tree is the number of nodes on the longest path between two leaves in the tree
Constraints
1 <= T <= 10
1 <= N <= 2*10^3
1 <= u,v <= N
1 <= S <= 10^9
Input Format
The first line of the input contains an Integer T, the total number of test cases.
The first line of each test case contains two space separated integers N and
S,the number of nodes in a tree and the integer S as mentioned in the problem statement.
Then the N-1 lines follow, each containing two space-separated integers u
and v representing that there is a bidirectional edge between the nodes u and v.
我无法制定一种以要求的方式将重量分配到所有边缘的策略。任何帮助都非常感谢。
答案 0 :(得分:0)
有两种情况:
S
-1个边缘之间尽可能均匀地划分N
。因此,答案是⌈S/(N-1)⌉
。测试#1就是这种情况。S
且答案为0。测试中的边1-4就是这种情况#2。因此,我们已减少了确定所有不属于任何直径的边的问题。有一个写得很好的答案here。