#include <iostream>
#include <vector>
using namespace std;

long long n, a[100009], b[100009], c[100009], s[100009], dist[100009], dp[100009]; vector<int>x[100009]; bool used[100009];
vector<pair<long long, long long>>X[200009];

long long dfs(int pos, int depth) {
	used[pos] = true;
	dist[pos] = depth;
	dp[pos] = 1;
	for (int i = 0; i < x[pos].size(); i++) {
		if (used[x[pos][i]] == true) continue;
		dp[pos] += dfs(x[pos][i], depth + 1);
	}
	return dp[pos];
}
void dfs2(int pos, long long depth) {
	if (used[pos] == true) return;
	dist[pos] = depth; used[pos] = true;
	for (int i = 0; i < X[pos].size(); i++) {
		dfs2(X[pos][i].first, depth + X[pos][i].second);
	}
}

int main() {
	cin >> n;
	for (int i = 1; i <= n - 1; i++) {
		cin >> a[i] >> b[i];
		x[a[i]].push_back(b[i]);
		x[b[i]].push_back(a[i]);
	}
	for (int i = 1; i <= n; i++) cin >> s[i];
	dfs(1, 0);
	for (int i = 1; i <= n - 1; i++) {
		if (dist[a[i]] > dist[b[i]]) swap(a[i], b[i]);
		if (s[b[i]] - s[a[i]] == 0) continue;
		else  c[i] = (s[b[i]] - s[a[i]]) / (n - dp[b[i]] * 2);
	}
	for (int i = 1; i <= n - 1; i++) {
		X[a[i]].push_back(make_pair(b[i], c[i]));
		X[b[i]].push_back(make_pair(a[i], c[i]));
	}
	for (int i = 1; i <= n; i++) used[i] = false;
	dfs2(1, 0);
	long long sum = 0; for (int i = 1; i <= n; i++) sum += dist[i];
	for (int i = 1; i <= n - 1; i++) {
		if (c[i] == 0) c[i] = (s[1] - sum) / (n / 2);
	}
	for (int i = 1; i <= n - 1; i++) {
		cout << c[i] << endl;
	}
	return 0;
}