// Ho-kago Tea Time

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = (int) 2e5;

int n;

vector<int> adj[MAXN + 5];

int type[MAXN + 5];

inline char safe_getchar()
{
	register char ch(getchar());
	while(!isdigit(ch)) ch = getchar();
	return ch;
}

inline void input()
{
	n = read<int>();
	for(int i = 1; i < n; ++i)
	{
		int u = read<int>(), v = read<int>();
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i = 1; i <= n; ++i) type[i] = safe_getchar() - '0';
}

const int INF = (int) 1e9;

int f[MAXN + 5], g[MAXN + 5], anc[MAXN + 5];

inline void dfs_f(int u, int fa)
{
	anc[u] = fa;

	f[u] = 0;
	for(auto v : adj[u]) if(v != fa)
	{
		dfs_f(v, u);
		chkmax(f[u], f[v] + 1);
	}
}

inline void dfs_g(int u, int fa)
{
	int deg = SZ(adj[u]) - 1;

	static int pre[MAXN + 5], suf[MAXN + 5];

	for(int i = 0; i <= deg; ++i)
	{
		int v = adj[u][i];
		pre[i] = suf[i] = v == fa ? 0 : f[v] + 1;
	}
	for(int i = 1; i <= deg; ++i) chkmax(pre[i], pre[i - 1]);
	for(int i = deg - 1; i >= 0; --i) chkmax(suf[i], suf[i + 1]);

	for(int i = 0; i <= deg; ++i)
	{
		int v = adj[u][i];
		if(v != fa)
		{
			int res = g[u];
			if(i > 0) chkmax(res, pre[i - 1]);
			if(i < deg) chkmax(res, suf[i + 1]);
			chkmax(g[v], res + 1);
		}
	}

	for(auto v : adj[u]) if(v != fa)
		dfs_g(v, u);
}

int size[MAXN + 5], p[MAXN + 5], q[MAXN + 5];

inline void dfs_pq(int u, int fa, int tot)
{
	p[u] = type[u] ? 0 : INF;

	size[u] = type[u];
	for(auto v : adj[u]) if(v != fa)
	{
		dfs_pq(v, u, tot);
		if(size[v]) chkmin(p[u], f[v] + 1);
		size[u] += size[v];
	}

	q[u] = size[u] == tot ? INF : g[u];
}

inline void solve()
{
	dfs_f(1, 0);
	dfs_g(1, 0);

	int tot = 0;
	for(int i = 1; i <= n; ++i) tot += type[i];
	dfs_pq(1, 0, tot);

	LL ans = 1;
	for(int u = 1; u <= n; ++u)
	{
		int l = type[u] ? 0 : min(p[u], q[u]), r = max(f[u], g[u]) - 1;
		for(auto v : adj[u])
		{
			if(v == anc[u]) chkmin(r, f[u] + 1);
			else chkmin(r, g[v]);
		}
		ans += max(0, r - l + 1);
	}
	printf("%lld\n", ans);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}


### Prompt

Please create a solution in CPP 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
// Ho-kago Tea Time

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = (int) 2e5;

int n;

vector<int> adj[MAXN + 5];

int type[MAXN + 5];

inline char safe_getchar()
{
	register char ch(getchar());
	while(!isdigit(ch)) ch = getchar();
	return ch;
}

inline void input()
{
	n = read<int>();
	for(int i = 1; i < n; ++i)
	{
		int u = read<int>(), v = read<int>();
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i = 1; i <= n; ++i) type[i] = safe_getchar() - '0';
}

const int INF = (int) 1e9;

int f[MAXN + 5], g[MAXN + 5], anc[MAXN + 5];

inline void dfs_f(int u, int fa)
{
	anc[u] = fa;

	f[u] = 0;
	for(auto v : adj[u]) if(v != fa)
	{
		dfs_f(v, u);
		chkmax(f[u], f[v] + 1);
	}
}

inline void dfs_g(int u, int fa)
{
	int deg = SZ(adj[u]) - 1;

	static int pre[MAXN + 5], suf[MAXN + 5];

	for(int i = 0; i <= deg; ++i)
	{
		int v = adj[u][i];
		pre[i] = suf[i] = v == fa ? 0 : f[v] + 1;
	}
	for(int i = 1; i <= deg; ++i) chkmax(pre[i], pre[i - 1]);
	for(int i = deg - 1; i >= 0; --i) chkmax(suf[i], suf[i + 1]);

	for(int i = 0; i <= deg; ++i)
	{
		int v = adj[u][i];
		if(v != fa)
		{
			int res = g[u];
			if(i > 0) chkmax(res, pre[i - 1]);
			if(i < deg) chkmax(res, suf[i + 1]);
			chkmax(g[v], res + 1);
		}
	}

	for(auto v : adj[u]) if(v != fa)
		dfs_g(v, u);
}

int size[MAXN + 5], p[MAXN + 5], q[MAXN + 5];

inline void dfs_pq(int u, int fa, int tot)
{
	p[u] = type[u] ? 0 : INF;

	size[u] = type[u];
	for(auto v : adj[u]) if(v != fa)
	{
		dfs_pq(v, u, tot);
		if(size[v]) chkmin(p[u], f[v] + 1);
		size[u] += size[v];
	}

	q[u] = size[u] == tot ? INF : g[u];
}

inline void solve()
{
	dfs_f(1, 0);
	dfs_g(1, 0);

	int tot = 0;
	for(int i = 1; i <= n; ++i) tot += type[i];
	dfs_pq(1, 0, tot);

	LL ans = 1;
	for(int u = 1; u <= n; ++u)
	{
		int l = type[u] ? 0 : min(p[u], q[u]), r = max(f[u], g[u]) - 1;
		for(auto v : adj[u])
		{
			if(v == anc[u]) chkmin(r, f[u] + 1);
			else chkmin(r, g[v]);
		}
		ans += max(0, r - l + 1);
	}
	printf("%lld\n", ans);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}


```