#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
vector<int> E[202020];

vector<pair<int,int>> V[202020];
vector<pair<int,int>> L[202020],R[202020];
int A[202020],B[202020];
ll ret=0;
map<int,pair<int,int>> memo[202020];

pair<int,int> dfs(int cur,int pre) {
	V[cur].resize(E[cur].size());
	
	int D=0, is=S[cur], i;
	FOR(i,E[cur].size()) {
		int r=E[cur][i];
		if(r!=pre) {
			V[cur][i]=dfs(r,cur);
			V[cur][i].first++;
			D=max(D,V[cur][i].first);
			is|=V[cur][i].second;
		}
	}
	return memo[cur][pre] = make_pair(D,is);
}

void dfs2(int cur,int pre,pair<int,int> par) {
	par.first++;
	int i;
	
	FOR(i,E[cur].size()) {
		int r=E[cur][i];
		if(r==pre) V[cur][i]=par;
	}
	L[cur].resize(E[cur].size());
	R[cur].resize(E[cur].size());
	L[cur][0].second = R[cur].back().second = S[cur];
	for(i=1;i<L[cur].size();i++) {
		L[cur][i].first=max(L[cur][i-1].first,V[cur][i-1].first);
		L[cur][i].second=L[cur][i-1].second | V[cur][i-1].second;
	}
	for(i=R[cur].size()-2;i>=0;i--) {
		R[cur][i].first=max(R[cur][i+1].first,V[cur][i+1].first);
		R[cur][i].second=R[cur][i+1].second | V[cur][i+1].second;
	}
	FOR(i,E[cur].size()) {
		int r=E[cur][i];
		if(r!=pre) {
			pair<int,int> p={max(L[cur][i].first,R[cur][i].first),L[cur][i].second|R[cur][i].second};
			memo[cur][r]=p;
			dfs2(r,cur,p);
		}
	}
	
}

void centerv(int a) {
	vector<pair<int,int>> C=V[a];
	
	C.push_back({0,S[a]});
	C.push_back({0,S[a]});
	
	sort(ALL(C));
	reverse(ALL(C));
	int Rmax=C[1].first;
	int Rmin=201010;
	FORR(v,C) if(v.second) Rmin=min(Rmin,v.first);
	
	if(Rmin<=Rmax) {
		ret+=Rmax-Rmin+1;
	}
}

void centere(int a,int b) {
	pair<int,int> p[2]={memo[a][b],memo[b][a]};
	
	if(p[0].first<p[1].first) {
		ret+=p[0].second;
	}
	else if(p[0].first>p[1].first) {
		ret+=p[1].second;
	}
	else {
		ret++;
	}

}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>A[i]>>B[i];
		A[i]--, B[i]--;
		E[A[i]].push_back(B[i]);
		E[B[i]].push_back(A[i]);
	}
	cin>>S;
	FORR(c,S) c-='0';
	
	auto p=dfs(0,-1);
	dfs2(0,-1,{0,0});
	FOR(i,N) centerv(i);
	FOR(i,N-1) centere(A[i],B[i]);
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}

### Prompt

Create a solution in CPP for 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 signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
vector<int> E[202020];

vector<pair<int,int>> V[202020];
vector<pair<int,int>> L[202020],R[202020];
int A[202020],B[202020];
ll ret=0;
map<int,pair<int,int>> memo[202020];

pair<int,int> dfs(int cur,int pre) {
	V[cur].resize(E[cur].size());
	
	int D=0, is=S[cur], i;
	FOR(i,E[cur].size()) {
		int r=E[cur][i];
		if(r!=pre) {
			V[cur][i]=dfs(r,cur);
			V[cur][i].first++;
			D=max(D,V[cur][i].first);
			is|=V[cur][i].second;
		}
	}
	return memo[cur][pre] = make_pair(D,is);
}

void dfs2(int cur,int pre,pair<int,int> par) {
	par.first++;
	int i;
	
	FOR(i,E[cur].size()) {
		int r=E[cur][i];
		if(r==pre) V[cur][i]=par;
	}
	L[cur].resize(E[cur].size());
	R[cur].resize(E[cur].size());
	L[cur][0].second = R[cur].back().second = S[cur];
	for(i=1;i<L[cur].size();i++) {
		L[cur][i].first=max(L[cur][i-1].first,V[cur][i-1].first);
		L[cur][i].second=L[cur][i-1].second | V[cur][i-1].second;
	}
	for(i=R[cur].size()-2;i>=0;i--) {
		R[cur][i].first=max(R[cur][i+1].first,V[cur][i+1].first);
		R[cur][i].second=R[cur][i+1].second | V[cur][i+1].second;
	}
	FOR(i,E[cur].size()) {
		int r=E[cur][i];
		if(r!=pre) {
			pair<int,int> p={max(L[cur][i].first,R[cur][i].first),L[cur][i].second|R[cur][i].second};
			memo[cur][r]=p;
			dfs2(r,cur,p);
		}
	}
	
}

void centerv(int a) {
	vector<pair<int,int>> C=V[a];
	
	C.push_back({0,S[a]});
	C.push_back({0,S[a]});
	
	sort(ALL(C));
	reverse(ALL(C));
	int Rmax=C[1].first;
	int Rmin=201010;
	FORR(v,C) if(v.second) Rmin=min(Rmin,v.first);
	
	if(Rmin<=Rmax) {
		ret+=Rmax-Rmin+1;
	}
}

void centere(int a,int b) {
	pair<int,int> p[2]={memo[a][b],memo[b][a]};
	
	if(p[0].first<p[1].first) {
		ret+=p[0].second;
	}
	else if(p[0].first>p[1].first) {
		ret+=p[1].second;
	}
	else {
		ret++;
	}

}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>A[i]>>B[i];
		A[i]--, B[i]--;
		E[A[i]].push_back(B[i]);
		E[B[i]].push_back(A[i]);
	}
	cin>>S;
	FORR(c,S) c-='0';
	
	auto p=dfs(0,-1);
	dfs2(0,-1,{0,0});
	FOR(i,N) centerv(i);
	FOR(i,N-1) centere(A[i],B[i]);
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}

```