#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=2147483647;
char str[200010];
int h[200010],to[400010],nex[400010],fa[200010],d[200010],s[200010],f[200010],g[200010],tmp[200010],M;
void add(int a,int b){
	M++;
	to[M]=b;
	nex[M]=h[a];
	h[a]=M;
}
void dfs(int x){
	s[x]=str[x]=='1';
	for(int i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x]){
			fa[to[i]]=x;
			dfs(to[i]);
			s[x]+=s[to[i]];
		}
	}
}
void dfs1(int x){
	for(int i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x]){
			dfs1(to[i]);
			f[x]=max(f[x],f[to[i]]+1);
		}
	}
}
void dfs2(int x){
	int i,j,M=0,p;
	for(i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x])tmp[++M]=f[to[i]];
	}
	for(i=M-1;i>0;i--)tmp[i]=max(tmp[i],tmp[i+1]);
	tmp[M+1]=-inf;
	p=-inf;
	for(i=h[x],j=1;i;i=nex[i]){
		if(to[i]!=fa[x]){
			g[to[i]]=max(max(p+2,g[x]+1),tmp[j+1]+2);
			p=max(p,f[to[i]]);
			j++;
		}
	}
	for(i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x])dfs2(to[i]);
	}
}
int gao(int x,int y){
	if(fa[y]==x){
		if(s[y]==0)return inf;
		return f[y]+1;
	}else{
		if(s[1]-s[x]==0)return inf;
		return g[x];
	}
}
int main(){
	int n,i,x,y,l,r,mx,se;
	ll ans;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
		d[x]++;
		d[y]++;
	}
	scanf("%s",str+1);
	dfs(1);
	dfs1(1);
	dfs2(1);
	ans=0;
	for(x=1;x<=n;x++){
		if(d[x]==1){
			ans+=str[x]=='1';
			continue;
		}
		mx=se=-inf;
		#define gay(t)\
			if(t>=mx){\
				se=mx;\
				mx=t;\
			}else if(t>se)\
				se=t;
		for(i=h[x];i;i=nex[i]){
			if(to[i]==fa[x]){
				gay(g[x])
			}else{
				gay(f[to[i]]+1)
			}
		}
		r=se;
		l=str[x]=='1'?0:inf;
		for(i=h[x];i;i=nex[i])l=min(l,gao(x,to[i]));
		if(l<=r)ans+=r-l+1;
	}
	for(i=2;i<=n;i++){
		x=i;
		if(f[x]<g[x]-1)
			ans+=s[x]!=0;
		else if(f[x]>g[x]-1)
			ans+=(s[1]-s[x])!=0;
		else
			ans++;
	}
	printf("%lld",ans);
}