#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(x, a, b) for(int x = (a); x <= (b); ++x)
#define rop(x, a, b) for(int x = (a); x < (b); ++x)
#define per(x, a, b) for(int x = (a); x >= (b); --x)
using namespace std;
typedef long long LL;
typedef double DB;
const int INF = 10000000;
LL as;
char S[200005];
struct tree {
	int mx[200005], sz[200005], smx[200005], sn[200005];
	int hd[200005], vr[400005], nt[400005], tt;
	void push(int x, int y) {
		vr[++tt] = y; nt[tt] = hd[x]; hd[x] = tt;
	}
	void dfs0(int nw, int en) {
		sz[nw] = S[nw] == '1';
		mx[nw] = 0;
		smx[nw] = -INF;
		sn[nw] = INF; 
		for(int i = hd[nw]; i; i = nt[i]) {
			if(vr[i] == en) continue;
			dfs0(vr[i], nw);
			if(mx[nw] < mx[vr[i]] + 1) {
				smx[nw] = mx[nw];
				mx[nw] = mx[vr[i]] + 1; 
			} else smx[nw] = max(smx[nw], mx[vr[i]] + 1);
			
			
			if(sz[vr[i]] == 0) continue;
			sz[nw] += sz[vr[i]];
			sn[nw] = min(sn[nw], mx[vr[i]] + 1);
			
		}
	}
	void dfs1(int nw, int en) {
//		if(smn[nw] == 0) smn[nw] = INF;
		if(nw != 1) {
			
			int k = 0;
			if(sz[1] - sz[nw]) {
				if(mx[nw] + 1 == mx[en]) k = smx[en];
				else k = mx[en];
				sn[nw] = min(sn[nw], k + 1); 
			}
			
			if(mx[nw] + 1 == mx[en]) {
				if(mx[nw] < smx[en] + 1) {
					smx[nw] = mx[nw];
					mx[nw] = smx[en] + 1; 
				} else smx[nw] = max(smx[nw], smx[en] + 1);
			} else {
				if(mx[nw] < mx[en] + 1) {
					smx[nw] = mx[nw]; 
					mx[nw] = mx[en] + 1; 
				} else smx[nw] = max(smx[nw], mx[en] + 1);
			}
			
		}
		for(int i = hd[nw]; i; i = nt[i]) {
			if(vr[i] == en) continue;
			dfs1(vr[i], nw);
		}
	}
//	d - 2 < smx
	void dfs2(int nw, int en) {
//		smx[nw] = max(0, smx[nw]) 
//		if(smx[nw] == 0)
		if(S[nw] == '1') as = as + min(smx[nw] + 1, mx[nw] - 1) + 1; 
		else as = as + max((min(smx[nw] + 1, mx[nw] - 1) - sn[nw] + 1), 0); 
//		cout << nw << " " << min(smx[nw] + 1, mx[nw] - 1) << endl;
		for(int i = hd[nw]; i; i = nt[i]) {
			if(vr[i] == en) continue;
			dfs2(vr[i], nw);
		}
	}
}T;
int n, x, y;
int main() {
	scanf("%d", &n);
	rop(i, 1, n) {
		scanf("%d%d", &x, &y);
		T.push(x, y);
		T.push(y, x);
	}
	scanf("%s", S + 1);
	T.dfs0(1, 0);
	T.dfs1(1, 0);
	T.dfs2(1, 0);
	cout << as + 1 << endl;
	return 0;
}
