题目描述
Problem Description
Snuke found a record of a tree with $ N $ vertices in an ancient ruin. Snuke summarized what he learned from this record as follows:
- The vertices of this tree are numbered $ 1, 2, ..., N $, and the edges are numbered $ 1, 2, ..., N-1 $.
- Edge $ i $ connects vertices $ a_i $ and $ b_i $ bidirectionally.
- Each edge's length is an integer between $ 1 $ and $ 10^{18} $ inclusive.
- The sum of the shortest distances from vertex $ i $ to vertices $ 1, ..., N $ is $ s_i $.
From this information, restore the length of each edge. It is guaranteed that it is possible to determine the lengths of the edges without contradicting the given information. Furthermore, it can be proven that the length of each edge is uniquely determined in such cases.
Input Format
The input is given from the standard input in the following format:
$ N $ $ a_1 $ $ b_1 $ $ : $ $ a_{N-1} $ $ b_{N-1} $ $ s_1 $ $ s_2 $ $ ... $ $ s_{N} $
Output Format
Output the answer in $ N-1 $ lines. The $ i $-th line should contain the length of edge $ i $.
Sample Input and Output
Sample Input #1
4
1 2
2 3
3 4
8 6 6 8
Sample Output #1
1
2
1
Sample Input #2
5
1 2
1 3
1 4
1 5
10 13 16 19 22
Sample Output #2
1
2
3
4
Sample Input #3
15
9 10
9 15
15 4
4 13
13 2
13 11
2 14
13 6
11 1
1 12
12 3
12 7
2 5
14 8
1154 890 2240 883 2047 2076 1590 1104 1726 1791 1091 1226 841 1000 901
Sample Output #3
5
75
2
6
7
50
10
95
9
8
78
28
89
8
Notes/Hints
Constraints
- $2 \leq N \leq 10^{5}$
- $1 \leq a_i, b_i \leq N$
- $1 \leq s_i \leq 10^{18}$
- The given graph is a tree.
- All given inputs are integers.
- It is possible to restore the lengths of the edges from the given information.
- Each edge's length is an integer between $ 1 $ and $ 10^{18} $ inclusive.
Partial Points
- For a dataset worth $ 300 $ points, $ a_i = i, b_i = i+1 $ holds.
- For another dataset worth $ 200 $ points, $N \geq 3, a_i = 1, b_i = i+1$ holds.
Sample Explanation 1
- The given record is a tree as shown in the following diagram:

Sample Explanation 2
- The given record is a tree as shown in the following diagram:

输入格式
见题面 Input 部分
输出格式
见题面 Output 部分
样例输入
4
1 2
2 3
3 4
8 6 6 8
样例输出
1
2
1