#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
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;
typedef pair<long long, long long> PLL;


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

const int MAX = 2 * 1000 * 100 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;

vector<int> g[MAX];
vector<int> SMIN[MAX];
vector<int> SMAX[MAX];
string s;
int PMAX[MAX];
int P[MAX];
int CNT[MAX];
int H[MAX];

void dfs(int v, int p)
{
	int ind = -1;
	FOR(i, 0, SZ(g[v]))
	{
		if (g[v][i] == p)
		{
			ind = i;
			break;
		}
	}

	if (ind != -1)
	{
		g[v].erase(g[v].begin() + ind);
	}
	
	CNT[v] = s[v] == '1';
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs(to, v);
		H[v] = max(H[v], H[to] + 1);
		CNT[v] += CNT[to];
	}
}

void dfs1(int v)
{
	int pmax = -INF;
	int pmin = INF;

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];

		PMAX[to] = max(pmax + 1, PMAX[v] + 1);
		if (i + 1 != SZ(g[v])) PMAX[to] = max(PMAX[to], SMAX[v][i + 1] + 1);

		pmax = max(pmax, H[to] + 1);
		pmin = min(pmin, H[to] + 1);
	}

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs1(to);
	}
}

vector<int> A;
int getMax2(int v)
{
	A.clear();
	A.push_back(PMAX[v]);
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		A.push_back(H[to] + 1);
	}

	sort(ALL(A));
	reverse(ALL(A));
	if (SZ(g[v]) == 0)
	{
		if (A[0] > 1) return 1;
		return 0;
	}

	int ans = A[1] + 1;
	while (ans >= A[0]) ans--;

	return ans;
}

int getMin(int v)
{
	int ans = INF;
	if (CNT[0] != CNT[v])
	{
		ans = min(ans, PMAX[v]);
	}

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		if (CNT[to] != 0)
		{
			ans = min(ans, H[to] + 1);
		}
	}


	return ans;
}

//#define DEBUG
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n - 1)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	cin >> s;
	dfs(0, 0);
#ifdef DEBUG
	cout << "H=" << endl;
	FOR(i, 0, n)
	{
		cout << i + 1 << " " << H[i] << endl;
	}
#endif
	FOR(v, 0, n)
	{
		SMIN[v].assign(SZ(g[v]), INF);
		SMAX[v].assign(SZ(g[v]), -INF);

		RFOR(i, SZ(g[v]), 0)
		{
			int to = g[v][i];
			if (i + 1 != SZ(g[v])) SMIN[v][i] = SMIN[v][i + 1];
			SMIN[v][i] = min(SMIN[v][i], H[to] + 1);

			if (i + 1 != SZ(g[v])) SMAX[v][i] = SMAX[v][i + 1];
			SMAX[v][i] = max(SMAX[v][i], H[to] + 1);
		}
	}

#ifdef DEBUG
	cout << "SMAX" << endl;
	FOR(i, 0, n)
	{
		cout << i + 1 << ": ";
		FOR(j, 0, SZ(g[i]))
		{
			cout << SMAX[i][j] << " ";
		}
		cout << endl;
	}
#endif
	PMAX[0] = -INF;
	if (SZ(g[0]) == 1)
	{
		PMAX[0] = 0;
	}
	dfs1(0);
	LL ans = 0;
#ifdef DEBUG
	cout << "PMAX=" << endl;
	FOR(i, 0, n)
	{
		cout << i + 1 << " " << PMAX[i] << endl;
	}

	cout << "2max" << endl;
	FOR(i, 0, n)
	{
		cout << i + 1 << " " << getMax2(i) << endl;
	}

	cout << "min" << endl;
	FOR(i, 0, n)
	{
		cout << i + 1 << " " << getMin(i) << endl;
	}
#endif

	FOR(v, 0, SZ(s))
	{
		if (s[v] == '1')
		{
			ans += getMax2(v) + 1;
			continue;
		}

		//cout << "!!" << getMax2(v) << " " << getMin(v) << endl;
		ans += max(getMax2(v) - getMin(v) + 1, 0);
	}
	
	cout << ans + 1 << endl;
}
### Prompt

Please formulate a CPP solution to 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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
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;
typedef pair<long long, long long> PLL;


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

const int MAX = 2 * 1000 * 100 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;

vector<int> g[MAX];
vector<int> SMIN[MAX];
vector<int> SMAX[MAX];
string s;
int PMAX[MAX];
int P[MAX];
int CNT[MAX];
int H[MAX];

void dfs(int v, int p)
{
	int ind = -1;
	FOR(i, 0, SZ(g[v]))
	{
		if (g[v][i] == p)
		{
			ind = i;
			break;
		}
	}

	if (ind != -1)
	{
		g[v].erase(g[v].begin() + ind);
	}
	
	CNT[v] = s[v] == '1';
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs(to, v);
		H[v] = max(H[v], H[to] + 1);
		CNT[v] += CNT[to];
	}
}

void dfs1(int v)
{
	int pmax = -INF;
	int pmin = INF;

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];

		PMAX[to] = max(pmax + 1, PMAX[v] + 1);
		if (i + 1 != SZ(g[v])) PMAX[to] = max(PMAX[to], SMAX[v][i + 1] + 1);

		pmax = max(pmax, H[to] + 1);
		pmin = min(pmin, H[to] + 1);
	}

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs1(to);
	}
}

vector<int> A;
int getMax2(int v)
{
	A.clear();
	A.push_back(PMAX[v]);
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		A.push_back(H[to] + 1);
	}

	sort(ALL(A));
	reverse(ALL(A));
	if (SZ(g[v]) == 0)
	{
		if (A[0] > 1) return 1;
		return 0;
	}

	int ans = A[1] + 1;
	while (ans >= A[0]) ans--;

	return ans;
}

int getMin(int v)
{
	int ans = INF;
	if (CNT[0] != CNT[v])
	{
		ans = min(ans, PMAX[v]);
	}

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		if (CNT[to] != 0)
		{
			ans = min(ans, H[to] + 1);
		}
	}


	return ans;
}

//#define DEBUG
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n - 1)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	cin >> s;
	dfs(0, 0);
#ifdef DEBUG
	cout << "H=" << endl;
	FOR(i, 0, n)
	{
		cout << i + 1 << " " << H[i] << endl;
	}
#endif
	FOR(v, 0, n)
	{
		SMIN[v].assign(SZ(g[v]), INF);
		SMAX[v].assign(SZ(g[v]), -INF);

		RFOR(i, SZ(g[v]), 0)
		{
			int to = g[v][i];
			if (i + 1 != SZ(g[v])) SMIN[v][i] = SMIN[v][i + 1];
			SMIN[v][i] = min(SMIN[v][i], H[to] + 1);

			if (i + 1 != SZ(g[v])) SMAX[v][i] = SMAX[v][i + 1];
			SMAX[v][i] = max(SMAX[v][i], H[to] + 1);
		}
	}

#ifdef DEBUG
	cout << "SMAX" << endl;
	FOR(i, 0, n)
	{
		cout << i + 1 << ": ";
		FOR(j, 0, SZ(g[i]))
		{
			cout << SMAX[i][j] << " ";
		}
		cout << endl;
	}
#endif
	PMAX[0] = -INF;
	if (SZ(g[0]) == 1)
	{
		PMAX[0] = 0;
	}
	dfs1(0);
	LL ans = 0;
#ifdef DEBUG
	cout << "PMAX=" << endl;
	FOR(i, 0, n)
	{
		cout << i + 1 << " " << PMAX[i] << endl;
	}

	cout << "2max" << endl;
	FOR(i, 0, n)
	{
		cout << i + 1 << " " << getMax2(i) << endl;
	}

	cout << "min" << endl;
	FOR(i, 0, n)
	{
		cout << i + 1 << " " << getMin(i) << endl;
	}
#endif

	FOR(v, 0, SZ(s))
	{
		if (s[v] == '1')
		{
			ans += getMax2(v) + 1;
			continue;
		}

		//cout << "!!" << getMax2(v) << " " << getMin(v) << endl;
		ans += max(getMax2(v) - getMin(v) + 1, 0);
	}
	
	cout << ans + 1 << endl;
}
```