#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=200010;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
LL ans;
char str[N];
int n,sz[N];
int bgn[N],nxt[N<<1],to[N<<1],E;
int Max[N],Maxc[N],Maxp[N],Min[N];
inline void add_edge(int u,int v){nxt[++E]=bgn[u],bgn[u]=E,to[E]=v;}
inline void dfs1(int u,int f)
{
	sz[u]=(str[u]=='1');
	Min[u]=inf;
	for(int v,i=bgn[u];i;i=nxt[i])
	{
		if((v=to[i])==f)continue;
		dfs1(v,u);
		sz[u]+=sz[v];
		if(sz[v])chkmin(Min[u],Max[v]+1);
		if(Max[v]+1>Max[u])
			Maxc[u]=Max[u],Max[u]=Max[v]+1,Maxp[u]=v;
		else
			chkmax(Maxc[u],Max[v]+1);
	}
}
inline void dfs2(int u,int f)
{
	for(int v,i=bgn[u];i;i=nxt[i])
	{
		if((v=to[i])==f)continue;
		if(Maxp[u]==v)
		{
			if(Maxc[u]+1>Max[v])
				Maxc[v]=Max[v],Max[v]=Maxc[u]+1,Maxp[v]=u;
			else
				chkmax(Maxc[v],Maxc[u]+1);
			if(sz[1]-sz[v]>0)chkmin(Min[v],Maxc[u]+1);
		}
		else
		{
			if(Max[u]+1>Max[v])
				Maxc[v]=Max[v],Max[v]=Max[u]+1,Maxp[v]=u;
			else
				chkmax(Maxc[v],Max[u]+1);
			if(sz[1]-sz[v]>0)chkmin(Min[v],Max[u]+1);
		}
		dfs2(v,u);
	}
	//printf("%d 1:%d p:%d 2:%d min:%d\n",u,Max[u],Maxp[u],Maxc[u],Min[u]);
	int high=min(Max[u]-1,Maxc[u]+1);
	if(str[u]=='1')
		ans+=high+1;
	else
	if(Min[u]<=high)
		ans+=high-Min[u]+1;
}
int main()
{
	int x,y;
	file();
	read(n);
	For(i,2,n)read(x),read(y),add_edge(x,y),add_edge(y,x);
	scanf("%s",str+1);
	dfs1(1,0);
	dfs2(1,0);
	printf("%lld\n",ans+1);
	return 0;
}
