// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#define int long long

using namespace std;

inline int read(){

	int f=1,ans=0;char c;

	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}

	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}

	return ans*f;

}

const int N=200011;

int cnt,d1[N],d2[N],d3[N],head[N],n,siz[N];

/*d1到叶子节点最长路径*/

/*d2为除掉一个子树的最长路径*/

/*d3为下界*/

struct node{

	int u,v,nex;

}x[N<<1];

void add(int u,int v){

	x[cnt].u=u,x[cnt].v=v,x[cnt].nex=head[u],head[u]=cnt++;

}

int son[N],sum;

char str[N];

void dfs1(int f,int fath){

	if(str[f]=='1') siz[f]=1,d3[f]=0,sum++;

	for(int i=head[f];i!=-1;i=x[i].nex){

		if(x[i].v==fath) continue;

		dfs1(x[i].v,f);

		if(d1[x[i].v]+1>=d1[f]) son[f]=x[i].v,d2[f]=d1[f],d1[f]=d1[x[i].v]+1;

		else if(d1[x[i].v]+1>=d2[f]) d2[f]=d1[x[i].v]+1;

		if(siz[x[i].v]) d3[f]=min(d3[f],d1[x[i].v]+1);

		siz[f]+=siz[x[i].v];

	}return; 

}

void dfs2(int f,int fath,int v){

	int nowv;

	for(int i=head[f];i!=-1;i=x[i].nex){

		

		if(x[i].v==fath) continue;

		

		if(son[f]==x[i].v) nowv=max(v,d2[f])+1;

		else nowv=max(v,d1[f])+1;

		

		if(nowv>=d1[x[i].v]) d2[x[i].v]=d1[x[i].v],d1[x[i].v]=nowv;

		else if(nowv>d2[x[i].v]) d2[x[i].v]=nowv;

		

		if(sum-siz[x[i].v]) d3[x[i].v]=min(d3[x[i].v],nowv);

		dfs2(x[i].v,f,nowv);

	}

}int ans;

signed main(){

//	freopen("make.in","r",stdin);

	memset(head,-1,sizeof(head));

	n=read();

	for(int i=1;i<n;i++){

		int u=read(),v=read();

		add(u,v),add(v,u);

	}

	scanf("%s",str+1);

	memset(d3,127,sizeof(d3));

	dfs1(1,0);



	dfs2(1,0,0);

//	for(int i=1;i<=n;i++) printf("d1(%d):%d d2(%d):%d d3(%d):%d\n",i,d1[i],i,d2[i],i,d3[i]);

	for(int i=1;i<=n;i++){

		if(str[i]=='1') ans+=max(min(d1[i],d2[i]+2),0LL);

		else ans+=max(min(d1[i],d2[i]+2)-d3[i],0LL);

	}printf("%lld\n",ans+1);

}


// Faster C++ solution for the same problem (measured speedup: 4.258640597359616x):
#include <iostream>

#include <cstdlib>

#include <cstdio>

#define N 200011

#define INF 0x7f7f7f7f

#define int long long

using namespace std;

int L[N],R[N],maxx1[N],maxx2[N],fa[N],siz[N],n,indexx[N],tot,Mark[N],ans;

char s[N];

struct apple{

	int v,nxt;

}edge[N*4];

void addedge(int x,int y){

	edge[++tot].v=y;

	edge[tot].nxt=indexx[x];

	indexx[x]=tot;

}

void dfs1(int u,int f){

	if(Mark[u]){

		siz[u]=1;

		L[u]=0;

	}

	else L[u]=INF;

	fa[u]=f;

	maxx1[u]=0;

	maxx2[u]=-INF;

	int t=indexx[u],vv;

	while(t){

		vv=edge[t].v;

		if(vv!=f){

			dfs1(vv,u);

			siz[u]+=siz[vv];

			if(maxx1[vv]+1>maxx1[u]){

				maxx2[u]=maxx1[u];

				maxx1[u]=maxx1[vv]+1;

			}

			else if(maxx1[vv]+1>maxx2[u]){

				maxx2[u]=maxx1[vv]+1;

			}

			if(siz[vv]) L[u]=min(L[u],maxx1[vv]+1);

		}

		t=edge[t].nxt;

	}

}

void dfs(int u){

	int temp;

	R[u]=min(maxx1[u]-1,maxx2[u]+1);

	if(R[u]>=L[u]) ans+=R[u]-L[u]+1;

	int t=indexx[u],vv;

	while(t){

		vv=edge[t].v;

		if(vv!=fa[u]){

			if(maxx1[u]==maxx1[vv]+1){

				temp=maxx2[u]+1;

			}

			else temp=maxx1[u]+1;

			if(temp>maxx1[vv]) maxx2[vv]=maxx1[vv],maxx1[vv]=temp;

			else if(temp>maxx2[vv]) maxx2[vv]=temp;

			if(siz[1]-siz[vv]) L[vv]=min(L[vv],temp);

			dfs(vv);

		}

		t=edge[t].nxt;

	}

}

signed main(){

	int x,y;

	scanf("%lld",&n);

	for(int i=1;i<n;i++){

		scanf("%lld%lld",&x,&y);

		addedge(x,y);

		addedge(y,x);

	}

	scanf("%s",s+1);

	for(int i=1;i<=n;i++) Mark[i]=s[i]-'0';

	dfs1(1,0);

	dfs(1);

	printf("%lld",ans+1);

	return 0;

}