#include <bits/stdc++.h>

typedef long long LL;
const int MAXN = 200010;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], tot;
void addedge(int b, int e) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e;
	nxt[++tot] = head[e]; to[head[e] = tot] = b;
}
int n;
char buf[MAXN]; int hav[MAXN];
int L[MAXN];
struct node {
	int fir, sec;
	void ins(int x) {
		if (x >= fir) sec = fir, fir = x;
		else sec = std::max(sec, x);
	}
} val[MAXN];
void dfs1(int u, int fa = 0) {
	hav[u] = buf[u] == '1';
	L[u] = hav[u] ? 0 : std::numeric_limits<int>::max();
	for (int i = head[u]; i; i = nxt[i])
		if (to[i] != fa) {
			dfs1(to[i], u);
			hav[u] += hav[to[i]];
			val[u].ins(val[to[i]].fir + 1);
			if (hav[to[i]]) L[u] = std::min(L[u], val[to[i]].fir + 1);
		}
}
long long ans = 1;
void dfs2(int u, int fa = 0, int ma = -1) {
	node tv = val[u]; tv.ins(ma);
	int l = L[u];
	if (hav[1] - hav[u]) l = std::min(l, ma);
	int r = std::min(tv.fir - 1, tv.sec + 1);
	if (l <= r) ans += r - l + 1;
	for (int i = head[u]; i; i = nxt[i]) if (to[i] != fa)
		dfs2(to[i], u, (val[to[i]].fir + 1 == tv.fir ? tv.sec : tv.fir) + 1);
}

int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1, t1, t2; i < n; ++i)
		std::cin >> t1 >> t2, addedge(t1, t2);
	std::cin >> buf + 1;
	dfs1(1); dfs2(1);
	std::cout << ans << std::endl;
	return 0;
}
