#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666;
int n,f[N],g[N],sz[N];Vi e[N];ll res;char s[N];
void dfs1(int u, int fa){
	sz[u]=s[u]=='1';
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa)
		dfs1(e[u][i],u),umax(f[u],f[e[u][i]]+1),sz[u]+=sz[e[u][i]];
}
void dfs2(int u,  int fa){
	int mx=-1e9,semx=-1e9;
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa)
		if(f[e[u][i]]>mx){semx=mx;mx=f[e[u][i]];}
		else if(f[e[u][i]]>semx)semx=f[e[u][i]];
		
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa)
		g[e[u][i]]=max(g[u]+1,mx==f[e[u][i]]?semx+2:mx+2),dfs2(e[u][i],u);
}
int query(int *a, int n, int x){return a[n]==x?a[n-1]:a[n];}
void dfs(int u, int fa){
	static int a[N];
	int len=0;a[++len]=g[u];a[++len]=0;
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa)a[++len]=f[e[u][i]]+1;
	sort(a+1,a+len+1);
	if(s[u]=='1')res+=a[len-1]+1;
	else{
		int mn=1e9;
		rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa){
			if(sz[e[u][i]]&&query(a,len,f[e[u][i]]+1)>=f[e[u][i]]+1)umin(mn,f[e[u][i]]+1);
		}else if(sz[1]-sz[u]&&query(a,len,g[u])>=g[u])umin(mn,g[u]);
		if(mn<=a[len-1])res+=a[len-1]-mn+1;
	}
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa){
		int v=e[u][i];dfs(e[u][i],u);
		int x=g[v]-1,y=f[v];bool ok=0;
		if(y==min(x,y))ok|=sz[v];
		if(x==min(x,y))ok|=sz[1]-sz[v];
		res+=ok;
	}
}
int main() {
	read(n);rep(i,1,n-1){
		int u,v;read(u);read(v);e[u].pb(v);e[v].pb(u);
	}
	scanf("%s",s+1);
	dfs1(1,0);dfs2(1,0);dfs(1,0);cout<<res;
	return 0;
}
