#include <bits/stdc++.h>
#define INF 200000000000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,int> P2;
int n;
vector<P> G[100005];
ll dist[100005];
ll ans[100005];
int cnt[100005];
int a[100005],b[100005];

ll labs(ll v){
	if(v<0LL)return -v;
	return v;
}

int dfs(int v,int p){
	int ans=1;
	for(int i=0;i<G[v].size();i++){
		if(G[v][i].first!=p){
			ans+=dfs(G[v][i].first,v);
		}
	}
	return (cnt[v]=ans);
}

ll dp[1000005];

ll dijk(int v){
	priority_queue<P2,vector<P2>,greater<P2> > que;
	que.push(P2(0,v));
	for(int i=0;i<n;i++){
		dp[i]=INF;
	}
	dp[v]=0;
	while(que.size()){
		P2 p=que.top();
		que.pop();
		if(dp[p.second]<p.first)continue;
		for(int i=0;i<G[p.second].size();i++){
			P e=G[p.second][i];
			if(ans[e.second]==-1){
				if(dp[p.second]<dp[e.first]){
					dp[e.first]=dp[p.second];
					que.push(P2(dp[e.first],e.first));
				}
			}else{
				if(dp[p.second]+ans[e.second]<dp[e.first]){
					dp[e.first]=dp[p.second]+ans[e.second];
					que.push(P2(dp[e.first],e.first));
				}
			}
		}
	}
	ll all=0;
	for(int i=0;i<n;i++){
		all+=dp[i];
	}
	return all;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		scanf("%d%d",&a[i],&b[i]);
		a[i]--;
		b[i]--;
		G[a[i]].push_back(P(b[i],i));
		G[b[i]].push_back(P(a[i],i));
	}
	for(int i=0;i<n;i++){
		scanf("%lld",&dist[i]);
	}
	dfs(0,-1);
	for(int i=0;i<n-1;i++){
		int nv=min(cnt[a[i]],cnt[b[i]]);
		if(nv*2==n){
			ans[i]=-1;
		}else{
			ll av=min(n-nv,nv);
			ll bv=max(n-nv,nv);
			ans[i]=labs(dist[a[i]]-dist[b[i]])/(bv-av);
		}
	}
	for(int i=0;i<n-1;i++){
		if(ans[i]==-1){
			ll val=dijk(a[i]);
			ans[i]=(dist[a[i]]-val)/((ll)n/2);
		}
		printf("%lld\n",ans[i]);
	}
	return 0;
}