#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 2e5 + 7, inf = 1e9 + 7;
int n, edc;
int head[N], L[N], R[N], mi[N][2], mx[N][2], g[N], has[N], cnt[N], fh[N];
LL ans;
char s[N];
struct edge { int lst, to;}e[N << 1];
void Add(int a, int b) {
	e[++edc] = (edge){ head[a], b}, head[a] = edc;
	e[++edc] = (edge){ head[b], a}, head[b] = edc;
}
void dfs1(int u, int fa) {
	mi[u][0] = mi[u][1] = inf;
	if(s[u] == '1') has[u] = 1, cnt[u] = 1;
	go(u) if(v ^ fa) {
		dfs1(v, u);
		has[u] |= has[v];
		cnt[u] += has[v];
		if(mx[v][0] + 1 < mi[u][0]) mi[u][1] = mi[u][0], mi[u][0] = mx[v][0] + 1;
		else Min(mi[u][1], mx[v][0] + 1);
		if(mx[v][0] + 1 > mx[u][0]) mx[u][1] = mx[u][0], mx[u][0] = mx[v][0] + 1;
		else Max(mx[u][1], mx[v][0] + 1);
	}
}
void dfs2(int u, int fa) {
	go(u) if(v ^ fa) {
		g[v] = max(g[u], mx[v][0] + 1 == mx[u][0] ? mx[u][1] : mx[u][0]) + 1;
		fh[v] = fh[u] | (has[v] ? cnt[u] > 1 : cnt[u] > 0);
		dfs2(v, u);
	}
//	if((g[u] - 1 <= mx[u][0] && fh[u]) || (mx[u][0] <= g[u] - 1 && has[u])) printf("%d\n", u);
	if(u != 1)
	ans += (g[u] - 1 <= mx[u][0] && fh[u]) || (mx[u][0] <= g[u] - 1 && has[u]);
	if(s[u] == '1') {
		ans += (g[u] >= mx[u][0] ? mx[u][0] : max(mx[u][1], g[u])) + 1;
	}else {
		int R = g[u] >= mx[u][0] ? mx[u][0] : max(mx[u][1], g[u]);
		int L = fh[u] ? g[u] : inf;
		go(u) if(v ^ fa && has[v]) Min(L, mx[v][0] + 1);
		if(L <= R)
		ans += R - L + 1;
	}
}
int main() {
#ifdef fwat
	freopen("data.in", "r", stdin);
	freopen("data.out", "w", stdout);
#endif
	n = gi();
	rep(i, 1, n - 1) Add(gi(), gi());
	scanf("%s", s + 1);
	dfs1(1, 0);
	dfs2(1, 0);
	printf("%lld\n", ans);
	return 0;
}