#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;
}


### Prompt

In cpp, your task is to solve the following problem:

There is a tree with N vertices. The vertices are numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i. The lengths of all the edges are 1.

Snuke likes some of the vertices. The information on his favorite vertices are given to you as a string s of length N. For each 1 ≤ i ≤ N, s_i is `1` if Snuke likes vertex i, and `0` if he does not like vertex i.

Initially, all the vertices are white. Snuke will perform the following operation exactly once:

* Select a vertex v that he likes, and a non-negative integer d. Then, paint all the vertices black whose distances from v are at most d.



Find the number of the possible combinations of colors of the vertices after the operation.

Constraints

* 2 ≤ N ≤ 2×10^5
* 1 ≤ a_i, b_i ≤ N
* The given graph is a tree.
* |s| = N
* s consists of `0` and `1`.
* s contains at least one occurrence of `1`.

Input

The input is given from Standard Input in the following format:


N
a_1 b_1
a_2 b_2
:
a_{N - 1} b_{N - 1}
s


Output

Print the number of the possible combinations of colors of the vertices after the operation.

Examples

Input

4
1 2
1 3
1 4
1100


Output

4


Input

5
1 2
1 3
1 4
4 5
11111


Output

11


Input

6
1 2
1 3
1 4
2 5
2 6
100011


Output

8

### Response

```cpp
#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;
}


```