#include<stdio.h>
#include<queue>
#include<assert.h>
#include<tuple>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 1 << 18;
const int MM = 1000000007;

int N;
char D[MX];
vector<int> T[MX];
int lev[MX], vst[MX], d1[MX], d2[MX];
int cnt[MX], low[MX];

void bfs(int x, int d[MX]){
	queue<int> Q;
	for(int i = 0; i < MX; i++) d[i] = 0;
	Q.push(x); d[x] = 1;
	while(Q.size()){
		int p = Q.front(); Q.pop();
		for(int c : T[p]){
			if( d[c] ) continue;
			d[c] = d[p] + 1;
			Q.push(c);
		}
	}
}

int main()
{
	scanf("%d", &N);
	for(int i = 2; i <= N; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		T[a].push_back(b);
		T[b].push_back(a);
	}
	scanf("%s", D+1);
	
	bfs(1, d1);
	int c = 1, d = 1;
	for(int i = 2; i <= N; i++) if( d1[c] < d1[i] ) c = i;
	bfs(c, d1);
	for(int i = 2; i <= N; i++) if( d1[d] < d1[i] ) d = i;
	bfs(d, d2);
	
	for(int i = 1; i <= N; i++) cnt[i] = T[i].size();
	queue<int> Q;
	for(int i = 1; i <= N; i++){
		vst[i] = 0;
		if( T[i].size() == 1 ) Q.push(i), vst[i] = 1;
	}
	while(Q.size()){
		int p = Q.front(); Q.pop();
		for(int c : T[p]){
			if( vst[c] ) continue;
			lev[c] = max(lev[c], lev[p] + 1);
			if( --cnt[c] == 1 ) Q.push(c), vst[c] = 1;
		}
	}

	for(int i = 1; i <= N; i++) low[i] = 1e9;
	priority_queue<pii, vector<pii>, greater<pii>> Qu;
	for(int i = 1; i <= N; i++) if( D[i] == '1' ){
		low[i] = lev[i];
		Qu.emplace(low[i], i);
	}
	while(Qu.size()){
		int c = Qu.top().first, d = Qu.top().second; Qu.pop();
		if( low[d] != c ) continue;
		c = max(c, lev[d]);
		for(int e : T[d]){
			if( D[e] == '1' || low[e] <= c + 1) continue;
			low[e] = c+1;
			Qu.emplace(low[e], e);
		}
	}
	for(int i = 1; i <= N; i++) if( D[i] == '1' )low[i] = 0;

	ll ans = 1;
	for(int i = 1; i <= N; i++){
		int v = min(max(d2[i], d1[i])-2, lev[i]+1);
		if( v >= low[i] ) ans += v - low[i] + 1;
	}
	printf("%lld\n", ans);
}
