#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
struct edge
{
	int to;
	int no;
	int next;
}e[333333];
int pe=111111;
void insert(int a,int to,int no)
{
	e[pe]=(edge){to,no,e[a].next};
	e[a].next=pe++;
}
int siz[111111];
long long s[111111];
long long ans[111111];
int fa[111111];
void dfs(int o)
{
	siz[o]=1;
	for(register int p=e[o].next;p;p=e[p].next)
		if(e[p].to!=fa[o])
			fa[e[p].to]=o,dfs(e[p].to),siz[o]+=siz[e[p].to];
}
long long ss;
int main()
{
	int n=io::F();
	for(register int i=1;i<n;++i)
	{
		int a=io::F(),b=io::F();
		insert(a,b,i);
		insert(b,a,i);
	}
	for(register int i=1;i<=n;++i)s[i]=io::G();
	dfs(1);
	for(register int i=2;i<=n;++i)
		for(register int p=e[i].next;p;p=e[p].next)
			if(e[p].to==fa[i])
			{
				int o=i;
				if(siz[o]!=n-siz[o])ans[e[p].no]=(s[o]-s[fa[o]])/(n-siz[o]-siz[o]),ss+=siz[o]*ans[e[p].no];
			}
	for(register int i=2;i<=n;++i)
		for(register int p=e[i].next;p;p=e[p].next)
			if(e[p].to==fa[i])
			{
				int o=i;
				if(siz[o]==n-siz[o])ans[e[p].no]=(s[1]-ss)/siz[o];
			}
	for(register int i=1;i<n;++i)
		printf("%lld\n",ans[i]);
	return 0;
}


