#include<bits/stdc++.h>
using namespace std;
#define LL long long

const int maxn=2e5+10;

int n,reach[maxn],deep[maxn<<1],high[maxn],low[maxn];
int tote=1,TO[maxn<<1],NEXT[maxn<<1],FIR[maxn];
bool col[maxn],exist[maxn],black[maxn<<1];
LL Ans=1;

void addedge(int u,int v)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	FIR[u]=tote;
}

void dfs1(int u,int f)
{
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (v==f) continue;
		dfs1(v,u);
		reach[u]=max(reach[u],reach[v]+1);
		deep[p]=reach[v]+1;
	}
}

void dfs2(int u,int f)
{
	int mx=0,se=0;
	for (int p=FIR[u];p;p=NEXT[p])
		if (mx<deep[p]) se=mx,mx=deep[p];
		else if (se<deep[p]) se=deep[p];
	high[u]=min(mx-1,se+1);
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (v==f) continue;
		deep[p^1]=deep[p]==mx?se+1:mx+1;
		dfs2(v,u);
	}
}

void dfs3(int u,int f)
{
	if (col[u]) low[u]=0,exist[u]=1;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (v==f) continue;
		dfs3(v,u);
		exist[u]|=exist[v];
		black[p]=exist[v];
	}
}

void dfs4(int u,int f)
{
	int pos1=0,pos2=0;
	for (int p=FIR[u];p;p=NEXT[p])
		if (black[p])
		{
			if (pos1) pos2=p;
			else pos1=p;
			low[u]=min(low[u],deep[p]);
		}
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (v==f) continue;
		black[p^1]=col[u]||(pos1&&p!=pos1)||(pos2&&p!=pos2);
		dfs4(v,u);
	}
}

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d",&n);
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	for (i=1;i<=n;i++)
	{
		char c=getchar();
		while (c!='0'&&c!='1') c=getchar();
		col[i]=c=='1';
	}
	memset(high,0,sizeof(high));
	memset(low,0x3f3f3f3f,sizeof(low));
	dfs1(1,0);
	dfs2(1,0);
	dfs3(1,0);
	dfs4(1,0);
	for (i=1;i<=n;i++)
		if (low[i]<=high[i]) Ans+=high[i]-low[i]+1;
	printf("%lld\n",Ans);
}
