#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 200000
struct edge{int nx,t;}e[MN*2+5];
int h[MN+5],en,d[MN+5],S[MN+5];
char s[MN+5];
long long ans;
inline void ins(int x,int y)
{
	e[++en]=(edge){h[x],y};h[x]=en;
	e[++en]=(edge){h[y],x};h[y]=en;
}
void dfs(int x,int fa)
{
	S[x]=s[x]-'0'; 
	for(int i=h[x];i;i=e[i].nx)if(e[i].t!=fa)
	{
		dfs(e[i].t,x);
		d[x]=max(d[x],d[e[i].t]+1);
		S[x]+=S[e[i].t];
	}
}
void solve(int x,int fa,int df,int sf)
{
	if(fa&&min(S[x]?d[x]:1e9,sf?df-1:1e9)<=min(d[x],df-1))++ans;
	int d1=0,d2=0,d3=s[x]^'0'?0:1e9;
	for(int i=h[x];i;i=e[i].nx)if(e[i].t!=fa)
	{
		if(d[e[i].t]>=d1)d2=d1,d1=d[e[i].t]+1;
		else if(d[e[i].t]>=d2)d2=d[e[i].t]+1;
		if(S[e[i].t])d3=min(d3,d[e[i].t]+1);
	}
	for(int i=h[x];i;i=e[i].nx)if(e[i].t!=fa)
		solve(e[i].t,x,max(df,d1==d[e[i].t]+1?d2:d1)+1,sf+S[x]-S[e[i].t]);
	if(df>d1)d2=d1,d1=df;else if(df>d2)d2=df;
	if(sf)d3=min(d3,df);
	if(d3<=d2)ans+=d2-d3+1;
}
int main()
{
	int n=read(),i;
	for(i=1;i<n;++i)ins(read(),read());
	scanf("%s",s+1);
	dfs(1,0);solve(1,0,0,0);
	printf("%lld",ans);
}