#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long i64;

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define NR 201000

const int inf = 1e9;

vector<int> g[NR];
char s[NR];
int m1[NR], m2[NR], n, son[NR];
i64 ans;

void dfs(int x, int fa) {
	m2[x] = -inf; m1[x] = -1;
	for (int v : g[x]) if (v != fa) {
		dfs(v, x);
		if (m1[x] == m1[v]) son[x] = 0;

		if (m1[v] > m1[x]) m2[x] = m1[x], m1[x] = m1[v], son[x] = v;
		else if (m1[v] > m2[x]) m2[x] = m1[v];
	}
	++m1[x], ++m2[x];
//	printf("!!%d %d\n", m1[x], m2[x]);
}

bool calc(int x, int fa, int upper) {
//	printf("!%d %d\n", m1[x] - 1, upper);
	//upper = max(upper, m1[x] - 1);
	int lower = (s[x] == '1' ? 0 : +inf);
	
	int mx = 0;
	for (int v : g[x]) if (v != fa) {
	//	printf("%d->%d %d\n", v, x, mx);
		if (calc(v, x, max(upper, v != son[x] ? m1[x] : m2[x]) + 1)) {
			lower = min(lower, m1[v] + 1);
		}
		mx = m1[v] + 1;
	}

	
	if (fa == 0) upper = m1[x] + 1;
	upper = min(upper - 1, m1[x] + 1);
	//printf("%d %d %d\n", x, lower, upper);
	if (lower <= upper) ans += upper - lower + 1;
	return lower != inf;
}

bool cmp(int i, int j) { return m1[i] < m1[j]; }

int main() {
	scanf("%d", &n);
	iter(i, n - 1) {
		int x, y;
		scanf("%d%d", &x, &y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	scanf("%s", s + 1);
	int root;
	iter(i, n) if (s[i] == '1') root = i;
	dfs(root, 0);
	iter(i, n) sort(g[i].begin(), g[i].end(), cmp);
	
	calc(root, 0, 0);
	printf("%lld\n", ans);
	return 0;
}