#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=200005,inf=1047483647;
struct node { int y,next; } a[N<<1];
LL an;
int s[N],fa[N],d1[N],d2[N],C[N],d3[N],head[N],i,j,k,n,m,z,Z,S;
bool p[N];
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

void jb(int x,int y)
{
	a[++k]=(node){y,head[x]},head[x]=k,
	a[++k]=(node){x,head[y]},head[y]=k;
}

int dfs1(int w)
{
	s[w]=p[w];
	for (register int j=head[w];j;j=a[j].next)
	{
		int c=a[j].y;
		if (c!=fa[w])
		{
			fa[c]=w,z=dfs1(c)+1,s[w]+=s[c];
			if (z>d1[w])
				d2[w]=d1[w],d1[w]=z,C[w]=c;
			else
				d2[w]=max(d2[w],z);
		}
	}
	return d1[w];
}

void dfs2(int w)
{
	for (register int j=head[w];j;j=a[j].next)
	{
		int c=a[j].y;
		if (c!=fa[w])
			d3[c]=max(d3[w],C[w]==c?d2[w]:d1[w])+1,
			dfs2(c);
	}
}

int main()
{
	n=read(),k=1;
	for (i=1;i<n;++i) jb(read(),read());
	do c=getc(); while (c<'0'||c>'1');
	i=0;
	while (c>='0'&&c<='1') p[++i]=c-'0',c=getc(),S+=p[i];
	if (!S)
	{
		puts("0");
		return 0;
	}
	dfs1(1),dfs2(1);
	for (i=1;i<=n;++i)
	{
		z=max(d1[i],d3[i])-1,Z=p[i]?0:inf;
		for (j=head[i];j;j=a[j].next)
		{
			int c=a[j].y;
			z=min(z,(fa[c]==i?max(d3[i],C[i]==c?d2[i]:d1[i]):d1[i])+1);
			if (s[c])
				Z=min(Z,d1[c]+1);
		}
		if (S-s[i])
			Z=min(Z,d3[i]);
		if (z>=Z)
			an+=z-Z+1;
	}
	printf("%lld\n",an+1);
	return 0;
}