#include "bits/stdc++.h"
using namespace std;
const long long mod = 1000000007;
const int maxn = 100100;
vector<int> tr[maxn];
int a[maxn], b[maxn], c[maxn], sz[maxn];
long long s[maxn], dw[maxn], res[maxn];
int nsz[maxn], par[maxn];
void in(int cur){
    nsz[cur] = 1;
    for(int id : tr[cur]){
        int nxt = cur ^ c[id];
        if(nxt == par[cur]) continue;
        par[nxt] = cur;
        in(nxt);
        nsz[cur] += nsz[nxt];
    }
}
int n;
void solve(int cur, int pr = -1){
    sz[cur] = 1;
    dw[cur] = 0;
    for(int id : tr[cur]){
        int nxt = cur ^ c[id];
        if(nxt == pr) continue;
        solve(nxt, cur);
        sz[cur] += sz[nxt];
    }
    for(int id : tr[cur]){
        int nxt = cur ^ c[id];
        if(nxt == pr) continue;
        int den = ((n - sz[nxt] + 1) - 1 - sz[nxt]);
        if(den == 0){
            res[id] = (s[cur] - dw[nxt]) / (sz[nxt]);
        } else {
            res[id] = (s[nxt] - s[cur]) / den;
        }
        dw[cur] += dw[nxt] + (sz[nxt]) * res[id];
    }
}
int main(){
    scanf("%d", &n);
    for(int e = 0; e < n - 1; e++){
        scanf("%d %d", a + e, b + e); c[e] = a[e] ^ b[e];
        tr[a[e]].push_back(e);
        tr[b[e]].push_back(e);
    }
    for(int e = 1; e <= n; e++) scanf("%lld", s + e);
    in(1);
    vector<int> bad_edge;
    for(int e = 0; e < n - 1; e++){
        if(par[a[e]] == b[e]){
            if(n - nsz[a[e]] == nsz[a[e]]) bad_edge.push_back(e);
        } else {
            if(n - nsz[b[e]] == nsz[b[e]]) bad_edge.push_back(e);
        }
    }
    if(bad_edge.size()){
        assert(bad_edge.size() == 1);
        int u = a[bad_edge[0]], v = b[bad_edge[0]];
        solve(u, v);
        solve(v, u);
        long long s0 = s[u] - dw[u] - dw[v];
        long long s1 = s[v] - dw[u] - dw[v];
        res[bad_edge[0]] = (s0 / sz[v]);
    } else
        solve(1);

    for(int e = 0; e < n - 1; e++) cout << res[e] << endl;
	return 0;
}
