//by xiqiao
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
typedef long long ll;
int n;
char s[maxn];
int f[maxn],g[maxn],high[maxn],low[maxn],out[maxn],in[maxn];
vector <int> v[maxn];
void dfs(int x,int last){
	if(s[x]=='1')in[x]=1;
	for(int i=0;i<(int)v[x].size();i++)if(v[x][i]!=last){
		dfs(v[x][i],x);
		f[x]=max(f[v[x][i]]+1,f[x]);
		in[x]|=in[v[x][i]];
	}
}
void dfs2(int x,int last){
	int mx1=0,mx2=0,cut=0;
	for(int i=0;i<(int)v[x].size();i++)if(v[x][i]!=last){
		if(f[v[x][i]]+1>mx1)mx2=mx1,mx1=f[v[x][i]]+1;
		else if(f[v[x][i]]+1>mx2)mx2=f[v[x][i]]+1;
		cut+=in[v[x][i]];
	}
	for(int i=0;i<(int)v[x].size();i++)if(v[x][i]!=last){
		int y=v[x][i];
		if(f[y]+1==mx1)g[y]=max(g[x]+1,mx2+1);
		else g[y]=max(g[x]+1,mx1+1);
		out[y]=out[x];
		if(cut-in[y] || s[x]=='1')out[y]=1;
		dfs2(y,x);
	}
}
void dfs3(int x,int last){
	int mx1=g[x],mx2=0;
	for(int i=0;i<(int)v[x].size();i++)if(v[x][i]!=last){
		int y=v[x][i];
		if(f[y]+1>mx1)mx2=mx1,mx1=f[y]+1;
		else if(f[y]+1>mx2)mx2=f[y]+1;
	}
	high[x]=min(mx2+1,mx1-1);
	if(s[x]=='1')low[x]=0;
	else{
		low[x]=high[x]+1;
		if(out[x])low[x]=min(low[x],g[x]);
		for(int i=0;i<(int)v[x].size();i++)if(v[x][i]!=last){
			int y=v[x][i];
			if(in[y])low[x]=min(low[x],f[y]+1);
		}
	}
	for(int i=0;i<(int)v[x].size();i++)if(v[x][i]!=last){
		dfs3(v[x][i],x);
	}
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;scanf("%d%d",&x,&y);
		v[x].push_back(y);v[y].push_back(x);
	}
	scanf("%s",s+1);
	dfs(1,0);dfs2(1,0);
	dfs3(1,0);
	ll ans=0;
	for(int i=1;i<=n;i++)ans+=high[i]-low[i]+1;//cout<<low[i]<<" "<<high[i]<<endl;
	ans++;
	printf("%lld\n",ans);
	return 0;
}