#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
using namespace std;

#define mp make_pair

int main() {
        int n;
        scanf("%d", &n);
        vector<vector<int>> g(n);
        map<pair<int, int>, int> edge_i;
        map<int, pair<int, int>> i_edge;
        for (int i = 0; i < n - 1; i ++) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
                edge_i[mp(min(a, b), max(a, b))] = i;
                i_edge[i] = mp(min(a, b), max(a, b));
        }
        vector<long long> s(n);
        for (int i = 0; i < n; i ++) scanf("%lld", &s[i]);
        vector<int> sz(n);
        vector<long long> ans(n);
        //dfs
        function<void (int, int)> dfs = [&](int u, int prev) {
                sz[u] = 1;
                for (auto v : g[u]) if (v != prev) {
                        dfs(v, u);
                        sz[u] += sz[v];
                        long long diff = (n - sz[v]) - sz[v];
                        long long res = (diff == 0 ? 0 : (s[v] - s[u]) / diff);
                        ans[edge_i[mp(min(u, v), max(u, v))]] = res;
                }
        };
        //
        dfs(0, -1);
        for (int i = 0; i < n - 1; i ++) if (ans[i] == 0) {
                int u, v;
                tie(u, v) = i_edge[i];
                long long res = 0;
                //dfs2
                function<void (int, int)> dfs2 = [&](int u, int prev) {
                        for (auto v : g[u]) if (v != prev) {
                                dfs2(v, u);
                                res += sz[v] * ans[edge_i[mp(min(u, v), max(u, v))]];
                        }
                };
                //
                dfs2(0, -1);
                ans[i] = (s[0] - res) / (n / 2);
                break;
        }
        for (int i = 0; i < n - 1; i ++) printf("%lld\n", ans[i]);
        return 0;
}

