#include <bits/stdc++.h>

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;

struct Graph {
    Graph(const ll n)
    {
        edge.resize(n);
    }
    void addEdge(const ll from, const ll to)
    {
        edge[from].push_back(to);
    }
    vector<vector<ll>> edge;
};

ll dfs(const Graph& g_, Graph& g, const ll s, vector<ll>& sub)
{
    sub[s] = 1;
    for (const ll to : g_.edge[s]) {
        if (sub[to] == -1) {
            g.addEdge(s, to);
            sub[s] += dfs(g_, g, to, sub);
        }
    }
    return sub[s];
}

using P = pair<ll, ll>;
void ddfs(const Graph& g_, const ll s, const vector<ll>& w, vector<ll>& d, const map<P, ll>& ind)
{
    const ll di = d[s];
    for (const ll to : g_.edge[s]) {
        if (d[to] == -1) {
            d[to] = di + w[ind.at(make_pair(s, to))];
            ddfs(g_, to, w, d, ind);
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    Graph g_(N);
    vector<P> edge(N - 1);
    map<P, ll> ind;
    for (ll i = 0; i < N - 1; i++) {
        ll u, v;
        cin >> u >> v;
        u--, v--;
        g_.addEdge(u, v);
        g_.addEdge(v, u);
        edge[i] = make_pair(u, v);
        ind[make_pair(u, v)] = i;
        ind[make_pair(v, u)] = i;
    }
    vector<ll> d(N);
    for (ll i = 0; i < N; i++) {
        cin >> d[i];
    }
    Graph g(N);
    vector<ll> sub(N, -1);
    dfs(g_, g, 0, sub);
    vector<ll> w(N - 1, -1);
    for (ll i = 0; i < N - 1; i++) {
        const auto& e = edge[i];
        const ll u = e.first;
        const ll v = e.second;
        const ll sa = abs(N - 2 * min(sub[u], sub[v]));
        const ll dsa = abs(d[u] - d[v]);
        if (dsa > 0) {
            w[i] = dsa / sa;
        }
    }
    for (ll i = 0; i < N - 1; i++) {
        if (w[i] == -1) {
            w[i] = 0;
            const ll u = edge[i].first;
            const ll v = edge[i].second;
            vector<ll> dist(N, -1);
            dist[u] = 0;
            ddfs(g_, u, w, dist, ind);
            const ll sum = accumulate(dist.begin(), dist.end(), 0LL);
            w[i] = (d[u] - sum) / (N / 2);
            break;
        }
    }
    for (ll i = 0; i < N - 1; i++) {
        cout << w[i] << endl;
    }

    return 0;
}
