#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=200005;
int head[maxn],t[maxn<<1],ne[maxn<<1],num,n;
int dp[maxn],nr[maxn];
char s[maxn];
i64 ans=0;
inline void dfs1(int x,int f){
	dp[x]=0;nr[x]=n;if(s[x]=='1')nr[x]=0;
	forE(i,x)if(t[i]!=f){
		dfs1(t[i],x);
		dp[x]=max(dp[x],dp[t[i]]+1);
		nr[x]=min(nr[x],nr[t[i]]+1);
	}
}
inline void dfs2(int x,int f,int n1,int dp1){
	int maxi1=0,nd1=0,maxi2=0,nd2=0,tot=0,low=n;
	maxi1=dp1;nd1=n1;vector<int> son;
	if(nd1<n)low=min(low,maxi1);
	forE(i,x)if(t[i]!=f){
		tot++;son.pb(t[i]);
		if(nr[t[i]]!=n)low=min(low,dp[t[i]]+1);
		if(dp[t[i]]+1>maxi1){
			maxi2=maxi1;nd2=nd1;
			maxi1=dp[t[i]]+1;nd1=nr[t[i]]+1;
		}else if (dp[t[i]]+1>maxi2){
			maxi2=dp[t[i]]+1;nd2=nr[t[i]]+1;
		}
	}if(s[x]=='1')low=0;
	ans+=max(0,min(maxi1-1,maxi2+1)-low+1);
	vector<int> dpprmax(tot+2,0),dpsfmax(tot+2,0),nrprmin(tot+2,n),nrsfmin(tot+2,n);
	rep(i,1,tot){
		dpprmax[i]=max(dpprmax[i-1],dp[son[i-1]]+2);
		nrprmin[i]=min(nrprmin[i-1],nr[son[i-1]]+2);
	}	
	per(i,tot,1){
		dpsfmax[i]=max(dpsfmax[i+1],dp[son[i-1]]+2);
		nrsfmin[i]=min(nrsfmin[i+1],nr[son[i-1]]+2);
	}if(s[x]=='1')n1=0;
	rep(i,1,tot){
		dfs2(son[i-1],x,min(n1+1,min(nrprmin[i-1],nrsfmin[i+1])),max(max(dp1+1,dpprmax[i-1]),dpsfmax[i+1]));
	}
}
inline void addedge(int x,int y){
	ne[++num]=head[x];head[x]=num;t[num]=y;
	ne[++num]=head[y];head[y]=num;t[num]=x;
}
int main(){
	read(n);
	rep(i,1,n)head[i]=-1;
	rep(i,1,n-1){
		int x,y;read(x);read(y);
		addedge(x,y);
	}scanf("%s",s+1);
	dfs1(1,-1);
	dfs2(1,-1,n,0);
	ans++;
	printf("%lld\n",ans);
	return 0;
}
