#include <iostream>
#include <vector>

using namespace std;

struct edge{
    int to;
    long cost;
};

vector<int> G[100000];
vector<edge> G1[100000];

long s[100000];
long ans[100000];
int a[100000], b[100000];
long cnt[100000];
bool used[100000];
int N;

void clear(){
    for(int i = 0; i < N; i++) used[i] = false;
}

long dfs1(int v){
    //cout << v << ' ' << cnt[v] << endl;
    used[v] = true;
    long ret = 0;
    for(int i = 0; i < G1[v].size(); i++){
        if(!used[G1[v][i].to]){
            ret += (dfs1(G1[v][i].to) + G1[v][i].cost*cnt[G1[v][i].to]);
        }
    }
    return ret;
}

void dfs(int v){
    used[v] = true;
    cnt[v] = 1;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]){
            dfs(G[v][i]);
            cnt[v] += cnt[G[v][i]];
        }
    }
}

int main(){
    int eql = -1;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }
    dfs(0);
    for(int i = 0; i < N-1; i++){
        int l = min(cnt[a[i]], cnt[b[i]]);
        int r = N-l;
        if(r < l) swap(r, l);
        if(l == r){
            eql = i;
        }else{
            ans[i] = abs(s[a[i]]-s[b[i]])/(r-l);
        }
    }
    if(eql != -1){
        for(int i = 0; i < N-1; i++){
            G1[a[i]].push_back(edge{b[i], ans[i]});
            G1[b[i]].push_back(edge{a[i], ans[i]});
        }
        clear();
        long sum = dfs1(0);
        //cout << sum << ' ' << s[0] << endl;
        ans[eql] = (s[0]-sum)/(N/2);
    }
    for(int i = 0; i < N-1; i++){
        cout << ans[i] << endl;
    }
}
