#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
long long ans;
int n,m,i,j,sz[200005],d[200005],f[200005],g[200005];
vector<int> bi[200005];
string col;
void dfs1(int x,int fa)
{
	if(col[x]=='1'){
		sz[x]=1;d[x]=0;
	}
	else{
		d[x]=0x12121212;
	}
	ff(bi[x],it){
		if(*it==fa)continue;
		dfs1(*it,x);
		sz[x]+=sz[*it];if(sz[*it])d[x]=min(d[x],f[*it]+1);
		if(f[*it]+1>g[x]){
			g[x]=f[*it]+1;
		}
		if(g[x]>f[x]){
			swap(f[x],g[x]);
		}
	}
}
void dfs2(int x,int fa)
{
	int lim=min(f[x]-1,g[x]+1);
	ans+=max(0,lim-d[x]+1);
	ff(bi[x],it){
		if(*it==fa)continue;
		int tmp=(f[x]==f[*it]+1?g[x]:f[x])+1;
		if(sz[1]!=sz[*it])d[*it]=min(d[*it],tmp);
		if(tmp>g[*it]){
			g[*it]=tmp;
		}
		if(g[*it]>f[*it]){
			swap(f[*it],g[*it]);
		}
		dfs2(*it,x);
	}
}
int main()
{
	scanf("%d",&n);
	fz1(i,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		bi[x].push_back(y);
		bi[y].push_back(x);
	}
	rdst(col,200005);col=" "+col;
	dfs1(1,0);dfs2(1,0);
	cout<<ans+1<<endl;
	return 0;
}