#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;
typedef long long ll;

int n;
vector<P>E[200000];
ll cost[200000],ans[200000];
ll s[200000];
int sz[200000];

int id=-1;
void dfs(int v,int p,int idx){
	sz[v]=1;
	for(auto u:E[v]){
		if(u.second==p)continue;
		dfs(u.second,v,u.first);
		sz[v]+=sz[u.second];
	}
	if(p!=-1){
		if(n-2*sz[v]==0){id=idx;cost[v]=ans[idx]=0;}
		else cost[v]=ans[idx]=(s[v]-s[p])/(n-2*sz[v]);
	}
}
ll calc(int v,int p){
	ll res=0;
	for(auto u:E[v]){
		if(u.second==p)continue;
		res+=cost[u.second]*(ll)sz[u.second]+calc(u.second,v);
	}
	return res;
}
int main(){
	scanf("%d",&n);
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(P(i,b));
		E[b].push_back(P(i,a));
	}
	rep(i,n){
		scanf("%lld",&s[i]);
	}
	dfs(0,-1,-1);
	if(id!=-1)ans[id]=(s[0]-calc(0,-1))/(n/2);
	rep(i,n-1){
		printf("%lld\n",ans[i]);
	}
	
}