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

const int N=200100;
typedef long long ll;
ll ans;
int dis1[N],dis2[N],q[N],a[N],n,sz[N],mx[N];
vector<int>g[N];
char s[N];

int bfs(int x,int*dis){
	for(int i=1;i<=n;++i)dis[i]=-1;
	dis[x]=0;q[0]=x;
	int t=-1,w=0;
	while(t<w){
		int u=q[++t];
		for(int i:g[u])if(dis[i]==-1){
			dis[i]=dis[u]+1;q[++w]=i;
		}
	}
	return q[w];
}


void dfs(int x,int fa,int d){
	sz[x]=s[x]-'0';mx[x]=0;
	for(int i:g[x])if(i!=fa){
		dfs(i,x,d+1);sz[x]+=sz[i];mx[x]=max(mx[x],mx[i]+1);
		if(sz[i])ans++;
	}
	int mn=mx[x]+1;if(s[x]=='1')mn=0;
	for(int i:g[x])if(i!=fa&&sz[i])mn=min(mn,mx[i]+1);
	ans+=mx[x]-mn+1;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<n;++i){
		int x,y;cin>>x>>y;
		g[x].push_back(y);g[y].push_back(x);
	}
	cin>>(s+1);
	int p=bfs(1,dis1),q=bfs(p,dis2);bfs(q,dis1);
	int L=dis1[p];
	for(int i=1;i<=n;++i)
		if(dis1[i]+dis2[i]==L)a[dis1[i]]=i;
	if(L&1){
		dfs(a[L/2],a[L/2+1],L/2+1);dfs(a[L/2+1],a[L/2],L/2+1);
		if(sz[a[L/2]]||sz[a[L/2+1]])ans++;
	}else dfs(a[L/2],-1,L/2);
	cout<<ans<<'\n';
	return 0;
}
