#include <bits/stdc++.h>

#define MAXN 200005
#define INF 0x3f3f3f3f

typedef long long lint;

using namespace std;

struct data {
	int next, to;
	data(int next = 0, int to = 0):next(next), to(to) {}
}edge[MAXN << 1];

struct node {
	int maxd, state;
	node(int maxd = 0, int state = 0):maxd(maxd), state(state) {}

	bool operator < (const node b) const {
		return maxd < b.maxd;
	}
};

int n; 
int fa[MAXN], state[MAXN], maxd[MAXN], maxu[MAXN], se[MAXN], semaxd[MAXN];
int stated[MAXN], stateu[MAXN], target[MAXN], times[MAXN], deg[MAXN];
int head[MAXN], cnt;
lint ans = 0;

void connect(int u, int v) {
	edge[++cnt] = data(head[u], v);
	head[u] = cnt;
}

void DFS1(int u, int pre) {
	fa[u] = pre;
	times[u] = stated[u] = state[u];
	for (int i = head[u]; i; i = edge[i].next) {
		int v = edge[i].to;
		++deg[u];
		if (v == pre)
			continue;
		DFS1(v, u);
		stated[u] |= stated[v];
		if (stated[v]) {
			++times[u];
			target[u] = v;
		}
		if (maxd[v] + 1 > maxd[u]) {
			semaxd[u] = maxd[u];
			maxd[u] = maxd[v] + 1;
		}
		else if (maxd[v] + 1 > semaxd[u]) 
			semaxd[u] = maxd[v] + 1;
	}
}

void DFS2(int u, int pre) {
	if (u != 1) {
		if (maxd[fa[u]] == maxd[u] + 1)
			maxu[u] = semaxd[fa[u]] + 1;
		else 
			maxu[u] = maxd[fa[u]] + 1;
		maxu[u] = max(maxu[u], maxu[fa[u]] + 1);
		if ((stated[fa[u]] && times[fa[u]] > 1) || (stated[fa[u]] && !stated[fa[u]]))
			stateu[u] = 1;
	}
	for (int i = head[u]; i; i = edge[i].next) {
		int v = edge[i].to;
		if (v == pre)
			continue;
		DFS2(v, u);
	}
}

int main() {
	int size=256<<20;
//申请空间
char *p=(char*)malloc(size)+size;
__asm__("movl %0,%%esp\n"::"r"(p));
	freopen("1_01.txt", "r", stdin);
	freopen("a.txt", "w", stdout);
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		connect(u, v);
		connect(v, u);
	}
	for (int i = 1; i <= n; ++i)
		scanf("%1d", &state[i]);
	DFS1(1, 0);
	DFS2(1, 0);
	for (int u = 1; u <= n; ++u) {
		if ((maxd[u] < maxu[u] - 1 && stated[u]) || (maxd[u] > maxu[u] - 1 && stateu[u]) || (maxd[u] == maxu[u] - 1 && (stateu[u] || stated[u]))) {
			++ans;
			// cout << u << " type1\n";
		}
		int up = 0;
		if (maxu[u] > maxd[u])
			up = maxd[u];
		else 
			up = max(maxu[u], semaxd[u]);
		if (state[u]) {
			ans += up + 1;
			// cout << u << " type2\n";
		}
		else {
			int down = stateu[u] ? maxu[u] : INF;
			for (int i = head[u]; i; i = edge[i].next) {
				int v = edge[i].to;
				if (v == fa[u])
					continue;
				if (stated[v])
					down = min(down, maxd[v] + 1);
			}
			// cout << u << " type3\n";
			ans += max(0, up - down + 1);
		}
		// cout  << deg[u] << " " << maxd[u] << " " << maxu[u] << endl;
	}
	printf("%lld\n", ans);
}