#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 200200;

struct edge
{
	int x, y;

	int depth;
	int any;

	edge()
	{
		x = y = -1;
		depth = 0;
		any = 0;
	}
};

vector<edge> E;
VI g[MAX];
VI I[MAX];
VI L[MAX];
VI R[MAX];
VI L2[MAX];
VI R2[MAX];
int D[MAX];
int U[MAX];
int ANY[MAX];
char S[MAX];

int dfs1(int x, int p)
{
	int res = 0;
	ANY[x] = S[x] - '0';
	FOR (i, 0, SZ(g[x]))
	{
		int e = g[x][i];
		int to = E[e].y;
		if (to == p) continue;

		E[e].depth = dfs1(to, x);
		res = max(res, E[e].depth);

		if (ANY[to])
		{
			ANY[x] = 1;
			E[e].any = true;
		}
	}
	return res + 1;
}

void dfs2(int x, int p, int ind)
{
	if (ind != -1)
	{
		int r = I[x][ind];

		int mx = 0;
		int mx2 = 0;
		if (r)
		{
			mx = max(mx, L[p][r - 1]);
			mx2 = max(mx2, L2[p][r - 1]);
		}
		if (r < SZ(g[p]) - 1)
		{
			mx = max(mx, R[p][r + 1]);
			mx2 = max(mx2, R2[p][r + 1]);
		}

		mx++;

		int e = g[x][ind];
		mx2 = max(mx2, S[E[e].y] - '0');

		E[e].depth = mx;
		E[e].any = mx2;
	}

	L[x].resize(SZ(g[x]));
	R[x].resize(SZ(g[x]));

	L2[x].resize(SZ(g[x]));
	R2[x].resize(SZ(g[x]));

	int mx = 0;
	int mx2 = 0;

	U[x] = INF;

	FOR (i, 0, SZ(g[x]))
	{
		int e = g[x][i];
		int val = E[e].depth;

		L[x][i] = R[x][i] = val;
		L2[x][i] = R2[x][i] = E[e].any;

		if (E[e].any)
		{
			U[x] = min(U[x], E[e].depth);
		}

		if (val > mx)
		{
			mx2 = mx;
			mx = val;
		}
		else
		{
			if (val > mx2)
			{
				mx2 = val;
			}
		}
	}

	D[x] = min(mx - 1, mx2 + 1);

	FOR (i, 1, SZ(g[x]))
	{
		L[x][i] = max(L[x][i], L[x][i-1]);
		L2[x][i] = max(L2[x][i], L2[x][i-1]);
	}

	RFOR(i, SZ(g[x]) - 1, 0)
	{
		R[x][i] = max(R[x][i], R[x][i+1]);
		R2[x][i] = max(R2[x][i], R2[x][i+1]);
	}



	FOR (i,0 , SZ(g[x]))
	{
		int e = g[x][i];
		int to = E[e].y;

		if (to == p) continue;
		dfs2(to, x, I[x][i]);
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	scanf("%d", &n);
	FOR (i, 0, n-1)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;

		I[x].PB(SZ(g[y]));
		I[y].PB(SZ(g[x]));

		edge e;
		e.x = x; e.y = y;
		g[x].PB(SZ(E));
		E.PB(e);

		e.x = y; e.y = x;
		g[y].PB(SZ(E));
		E.PB(e);
	}

	scanf("%s", S);

	dfs1(0, -1);
	dfs2(0, -1, -1);

	LL res = 0;
	FOR (i, 0, n)
	{
		if (S[i] == '1') res += D[i] + 1;
		else
		{
			if (U[i] <= D[i])
			{
				res += D[i] - U[i] + 1;
			}
		}
	}
	res++;
	cout<<res<<endl;

	/*FOR (i, 0, n)
	{
		cout<<i<<' '<<D[i]<<' '<<U[i]<<endl;
	}
	cout<<endl;

	FOR (i, 0, SZ(E))
	{
		cout<<E[i].x<<' '<<E[i].y<<' '<<E[i].depth<<' '<<E[i].any<<endl;
	}*/



}
