//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=2e5+5,inf=0x3f3f3f3f;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
inline int max(R int x,R int y){return x>y?x:y;}
inline int min(R int x,R int y){return x<y?x:y;}
int d1[N],d2[N],d3[N],d4[N],sz[N],fa[N];
ll res;char s[N];int n;
void dfs1(int u){
	sz[u]=(s[u]=='1'),d3[u]=sz[u]?0:inf;
	go(u)if(v!=fa[u]){
		fa[v]=u,dfs1(v),sz[u]+=sz[v],cmax(d1[u],d1[v]+1);
		if(sz[v])cmin(d3[u],d1[v]+1);
	}
}
void dfs2(int u){
	if(fa[u])d4[fa[u]]=d2[u]-1;
	R int se=0,fi=0,to=0;
	go(u)if(v!=fa[u]){
		if(d1[v]+1>=fi)to=v,se=fi,fi=d1[v]+1;
		else cmax(se,d1[v]+1);
	}
	go(u)if(v!=fa[u]){
		d2[v]=max(v==to?se:fi,d2[u])+1;
		dfs2(v);
	}
}
int main(){
	scanf("%d",&n);
	for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	scanf("%s",s+1);
	dfs1(1),dfs2(1);
	fp(u,1,n){
		R int mn=min(d3[u],sz[u]==sz[1]?1e9:d2[u]);
		R int mx=max(d1[u],d2[u])-1;
		go(u)cmin(mx,(v==fa[u]?d1[u]:d4[v])+1);
		res+=max(mx-mn+1,0);
	}
	printf("%lld\n",res+1);
	return 0;
}