#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define pb push_back

using namespace std;

const int N = 200010;

inline void chkmax(int& x, int y){
	x = x > y ? x : y;
}

inline void chkmin(int &x, int y){
	x = x < y ? x : y;
}

struct Info{
	int Mx, x;

	Info(){
		Mx = x = 0;
	}

	void update(int v){
		if(v > Mx) x = Mx, Mx = v;
		else if(v > x) x = v;
	}

	int query(int v){
		return v == Mx ? x : Mx;
	}
};

Info Maxd[N];
int dep[N], cnt[N];
vector<int> G[N];
char S[N];
int n;

int Maxv[N], high[N], low[N];

void DFS_init(int o, int f){
	cnt[o] = S[o] == '1';
	low[o] = n;
	for(int v : G[o]){
		if(v == f) continue;
		DFS_init(v, o);
		cnt[o] += cnt[v];
		Maxd[o].update(dep[v] + 1);
	}
	dep[o] = Maxd[o].Mx;
}

long long ans = 1;

void DFS_work(int o, int f){
	high[o] = min(Maxd[o].Mx - 1, Maxd[o].x + 1);
	chkmin(low[o], S[o] == '1' ? 0 : high[o] + 1);
	for(int v : G[o]){
		if(v == f) continue;
		int x = Maxd[o].query(dep[v] + 1), y = dep[v];
		if(cnt[1] - cnt[v]) chkmin(low[v], x + 1);
		if(cnt[v]) chkmin(low[o], y + 1);
		Maxd[v].update(x + 1);
		DFS_work(v, o);
	}
	ans += high[o] - low[o] + 1;
}

int main(){
	scanf("%d", &n);
	For(i, 2, n){
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].pb(v), G[v].pb(u);
	}
	scanf("%s", S + 1);
	DFS_init(1, 0);
	DFS_work(1, 0);
	printf("%lld\n", ans);
	return 0;
}