#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(0);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

ll N;
VV<ll> edges;
V<ll> S;
map<PLL, ll> ecost;

PLL create_edge(ll a, ll b) { return make_pair(min(a, b), max(a, b)); }

ll dfs(ll now, ll pre) {
    ll csum = 1;
    for(ll nxt : edges[now]) {
        if(nxt == pre) continue;
        csum += dfs(nxt, now);
    }
    if(now == 0) return csum;
    auto edge = create_edge(now, pre);
    ll nuse = N - csum;
    ll puse = csum;
    ll dic_use = abs(nuse - puse);
    ll dic_s = abs(S[now] - S[pre]);
    if(dic_use) {
        ecost[edge] = dic_s / dic_use;
        DEBUG(now, pre, dic_use, dic_s, dic_s/dic_use);
    }
    return csum;
}

PLL dfs_check(ll now, ll pre, ll &ucnt, PLL &nd_edge) {
    ll csum = 1, ssum = 0;
    for(ll nxt : edges[now]) {
        if(nxt == pre) continue;
        ll a, b;
        tie(a, b) = dfs_check(nxt, now, ucnt, nd_edge);
        csum += a;
        ssum += b;
        auto edge = create_edge(now, nxt);
        auto ite = ecost.find(edge);
        if(ite == ecost.end()) {
            ucnt = a;
            nd_edge = edge;
        }
    }
    {
        auto ite = ecost.find(create_edge(now, pre));
        if(ite != ecost.end()) ssum += csum * (ite->second);
    }
    return make_pair(csum, ssum);
}

int main() {
    cin >> N;
    V<PLL> elis;
    edges.resize(N);
    S.resize(N);
    for(ll i = 1; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
        elis.push_back(create_edge(a, b));
    }
    for(ll &e : S) cin >> e;

    dfs(0, -1);
    ll ucnt = -1;
    PLL nd_edge;
    ll ssum = dfs_check(0, -1, ucnt, nd_edge).second;
    DEBUG(ucnt, ssum);
    if(ucnt != -1) {
        ll dic = S[0] - ssum;
        ecost[nd_edge] = dic / ucnt;
    }

    for(const auto &ele : elis) cout << ecost[ele] << endl;
    return 0;
}


Measured memory_bytes: 27376