#include <bits/stdc++.h>
using namespace std;
const int maxn = 400000 +10;
const int inf = 0x7f7f7f7f;
int read(){
	int x=0,flag=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')flag=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*flag;
}
char str[maxn];
int n,cnte;
int head[maxn],to[maxn*2],nxt[maxn*2];
int vis[maxn],Max1[maxn],Max2[maxn],dep[maxn],dis[maxn];
int siz[maxn];
int low[maxn],height[maxn];
void AddEdge(int x,int y){ ++cnte;to[cnte]=y;nxt[cnte]=head[x];head[x]=cnte; }
int Dfs(int x,int fa){
	siz[x]=vis[x];
	Max1[x] = Max2[x] = 0;
	dis[x] = inf; dep[x] = 0;

	for(int i=head[x];i;i=nxt[i])if(to[i]^fa){
		int tmp = Dfs(to[i],x); 
		siz[x] = siz[x] + tmp;

		if(tmp) dis[x] = min( dep[to[i]], dis[x] );

		dep[x] = max( dep[to[i]]+1, dep[x] );

		if( Max1[x] == 0 || dep[to[i]] > dep[Max1[x]] ){
			Max2[x] = Max1[x];
			Max1[x] = to[i]; 
		}
		else if( Max2[x] == 0 || dep[to[i]] > dep[Max2[x]] )Max2[x] = to[i];

	}	
//	printf("x:%d dep:%d Max1:%d Max2:%d\n",x,dep[x],Max1[x],Max2[x]);

	return siz[x];
}
void dfs(int x,int fa,int Lim){
//	printf("x:%d Lim:%d\n",x,Lim);

	int t1=dep[Max1[x]]+1,t2=dep[Max2[x]]+1;

	if(Max1[x]==0)t1=0;
	if(Max2[x]==0)t2=0;

	if(Lim>t1){t2=t1;t1=Lim;}
	else if(Lim>t2)t2=Lim;

//	printf("x:%d max1:%d max2:%d\n",x,t1,t2);
	height[x] = min(t2+1,t1-1) ;

	if(!vis[x])low[x]=min(dis[x]+1,((siz[1]-siz[x]>0)?Lim:inf));
	else low[x]=0;

//	printf("x:%d dis[x]:%d Lim:%d\n",x,dis[x],Lim);

	for(int i=head[x];i;i=nxt[i])if(to[i]^fa){
		if(to[i] == Max1[x]) dfs(to[i],x,max(Lim,((Max2[x])?dep[Max2[x]]+1:-inf))+1);
		else dfs(to[i],x,max(Lim,dep[Max1[x]]+1)+1);
	}
}

int main(){
	//freopen("test.in","r",stdin),freopen("test.out","w",stdout);
	n=read();
	for(int i=1;i<=n-1;i++){
		int x,y;
		x=read();y=read();
//		x=i;y=i+1;
		AddEdge(x,y);AddEdge(y,x);
	}

	scanf("%s",str+1);
	for(int i=1;i<=n;i++)if(str[i]=='1')vis[i]=1;

	Dfs(1,0);
	dfs(1,0,0);

	long long Ans=0;
	for(int i=1;i<=n;i++){
		if(low[i]<=height[i])Ans += 1LL * (height[i] - low[i] + 1);
//		printf("i:%d low:%d height:%d\n",i,low[i],height[i]);
	}
	printf("%lld",Ans+1);
	return 0;
}