#include <vector>
#include <iostream>
using namespace std;
struct edge {
	int to, id;
	edge() : to(-1), id(-1) {};
	edge(int to_, int id_) : to(to_), id(id_) {};
};
int n, eid = -1; vector<int> a, b, c; vector<long long> s, t; vector<vector<edge> > g;
void dfs(int pos, int pre) {
	c[pos] = 1;
	for (edge e : g[pos]) {
		if (e.to != pre) {
			dfs(e.to, pos);
			c[pos] += c[e.to];
			if (c[e.to] * 2 != n) {
				t[e.id] = (s[e.to] - s[pos]) / (n - 2 * c[e.to]);
			}
			else eid = e.id;
		}
	}
}
long long calc(int pos, int pre, long long cumdist) {
	long long ret = cumdist;
	for (edge e : g[pos]) {
		if (e.to != pre) {
			ret += calc(e.to, pos, cumdist + t[e.id]);
		}
	}
	return ret;
}
int main() {
	cin.tie(0);
	cin >> n;
	a = vector<int>(n - 1);
	b = vector<int>(n - 1);
	s = vector<long long>(n);
	g = vector<vector<edge> >(n);
	for (int i = 0; i < n - 1; ++i) {
		cin >> a[i] >> b[i]; --a[i], --b[i];
		g[a[i]].push_back(edge(b[i], i));
		g[b[i]].push_back(edge(a[i], i));
	}
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	c = vector<int>(n);
	t = vector<long long>(n - 1);
	dfs(0, -1);
	if (eid != -1) {
		long long cur = calc(a[eid], -1, 0);
		t[eid] = (s[a[eid]] - cur) / (n / 2);
	}
	for (int i = 0; i < n - 1; ++i) {
		cout << t[i] << '\n';
	}
	return 0;
}