#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
map<i_i, int> mp;
int parent[100500];
int number[100500];
vector<int> children[100050];
vector<int> path[100500];
ll N;
ll s[100050];
ll unknown = -1;
ll SIZE[100500];
ll sum[100050];
ll ans[100050];

void bfs1(int from) {
    SIZE[from] = 1;
    for(int i = 0; i < path[from].size(); i++) {
        int to = path[from][i];
        if(to == parent[from]) {
            int a = min(to, from);
            int b = max(to, from);
            number[from] = mp[{a, b}];
            continue;
        }
        parent[to] = from;
        children[from].push_back(to);
        bfs1(to);
        SIZE[from] += SIZE[to];
    }
}

void bfs2(int from) {
    for(int i = 0; i < children[from].size(); i++) {
        int to = children[from][i];
        bfs2(to);
    }
    if(from == 1) return;
    int p = parent[from];
    if(SIZE[from] * 2 == N) {
        unknown = from;
        sum[p] += sum[from];
        return;
    }
    ll delta = (N - SIZE[from]) - SIZE[from];
    ll cost = (s[from] - s[p]) / delta;
    ans[number[from]] = cost;
    sum[p] += sum[from] + cost * SIZE[from];
    return;
}

int main() {
    //cout.precision(10);
    cin >> N;
    for(int i = 1; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        if(a > b) swap(a, b);
        mp[{a, b}] = i;
        path[a].push_back(b);
        path[b].push_back(a);
    }
    for(int i = 1; i <= N; i++) {
        cin >> s[i];
    }
    parent[1] = 0;
    bfs1(1);
    for(int i = 1; i <= N; i++) {
        //cout << i << " " << SIZE[i] << " " << parent[i] << " " << number[i] << endl;
    }
    bfs2(1);
    if(unknown != -1) {
        ll delta = s[1] - sum[1];
        ll cost = delta / SIZE[unknown];
        ans[number[unknown]] = cost;
    }
    for(int i = 1; i < N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}
