#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 2e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, dpD[maxn], dpU[maxn], sum[maxn], psL[maxn], psR[maxn], par[maxn], low[maxn], high[maxn];
int arr[maxn], tail;
vector<int> graph[maxn];
char s[maxn];

void dfsD(int u, int prev = -1)
{
	sum[u] = (s[u] == '1');
	for (int i : graph[u])
		if (i != prev)
		{
			dfsD(i, u);
			dpD[u] = max(dpD[u], dpD[i] + 1);
			sum[u] += sum[i];
		}
}

void dfsU(int u, int prev = -1)
{
	par[u] = prev;
	if (prev != -1)
		dpU[u] = max(dpU[u], dpU[prev] + 1);

	for (int i = 0; i < graph[u].size(); i++)
	{
		int now = graph[u][i];
		if (now != prev)
			psL[i] = psR[i] = dpD[now];
		else
			psL[i] = psR[i] = -mod;
	}

	for (int i = 1; i < graph[u].size(); i++)
		psL[i] = max(psL[i], psL[i - 1]);
	for (int i = (int)graph[u].size() - 2; i >= 0; i--)
		psR[i] = max(psR[i], psR[i + 1]);

	/*cerr << "DFS_U " << u << ' ' << prev << ':' << endl;
	for (int i : graph[u])
		cerr << i << ' ';
	cerr << endl;
	for (int i = 0; i < graph[u].size(); i++)
		cerr << psL[i] << '_';
	cerr << endl;
	for (int i = 0; i < graph[u].size(); i++)
		cerr << psR[i] << '_';
	cerr << endl;*/

	for (int i = 0; i < graph[u].size(); i++)
	{
		int now = graph[u][i];
		if (now == prev)
			continue;
		if (i)
			dpU[now] = max(dpU[now], psL[i - 1] + 2);
		if (i < graph[u].size() - 1)
			dpU[now] = max(dpU[now], psR[i + 1] + 2);
		//cerr << "UPDATE " << now << ' ' << i << ' ' << dpU[now] << endl;
	}

	for (int i : graph[u])
		if (i != prev)
			dfsU(i, u);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		graph[--u].pb(--v);
		graph[v].pb(u);
	}
	cin >> s;

	if (n == 2)
	{
		if (s[0] == '1' && s[1] == '1')
			cout << 3 << endl;
		else
			cout << 2 << endl;
		return 0;
	}

	dfsD(0);
	dfsU(0);

	//for (int i = 0; i < n; i++)
	//	cerr << "DP " << dpD[i] << ' ' << dpU[i] << endl;

	for (int i = 0; i < n; i++)
	{
		tail = 0;
		if (dpU[i])
			arr[tail++] = dpU[i];
		for (int j : graph[i])
			if (j != par[i])
				arr[tail++] = dpD[j] + 1;
		sort(arr, arr + tail);
		if (tail == 1)
			high[i] = 1;
		else
		{
			if (arr[tail - 1] == arr[tail - 2])
				high[i] = arr[tail - 1] - 1;
			else
				high[i] = min(arr[tail - 1] - 1, arr[tail - 2] + 1);
		}
	}
	for (int i = 0; i < n; i++)
	{
		tail = 0;
		if (par[i] != -1 && sum[0] - sum[i] > 0)
			arr[tail++] = dpU[i];
		for (int j : graph[i])
			if (j != par[i] && sum[j])
				arr[tail++] = dpD[j] + 1;
		if (s[i] == '1')
			low[i] = 0;
		else
		{
			if (tail == 0)
				low[i] = high[i] + 1;
			else
			{
				low[i] = *min_element(arr, arr + tail);
				//cerr << "HERE " << low[i] << ' ' << dpU[i] << endl;
			}
		}
	}

	/*for (int i = 0; i < n; i++)
		cerr << "HIGH " << i << ':' << high[i] << endl;
	cerr << "______________" << endl;
	for (int i = 0; i < n; i++)
		cerr << "LOW " << i << ':' << low[i] << endl;*/

	ll ans = 1;
	for (int i = 0; i < n; i++)
	{
		//cerr << "VAL " << i << ':' << max(0, high[i] - low[i] + 1) << endl;
		ans += max(0, high[i] - low[i] + 1);
	}
	cout << ans << endl;
}

