#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=200005;
int head[maxn],t[maxn<<1],ne[maxn<<1],num,n;
int dp[maxn],nr[maxn];
char s[maxn];
i64 ans=0;
inline void dfs1(int x,int f){
	dp[x]=0;nr[x]=n;if(s[x]=='1')nr[x]=0;
	forE(i,x)if(t[i]!=f){
		dfs1(t[i],x);
		dp[x]=max(dp[x],dp[t[i]]+1);
		nr[x]=min(nr[x],nr[t[i]]+1);
	}
}
inline void dfs2(int x,int f,int n1,int dp1){
	int maxi1=0,nd1=0,maxi2=0,nd2=0,tot=0,low=n;
	maxi1=dp1;nd1=n1;vector<int> son;
	if(nd1<n)low=min(low,maxi1);
	forE(i,x)if(t[i]!=f){
		tot++;son.pb(t[i]);
		if(nr[t[i]]!=n)low=min(low,dp[t[i]]+1);
		if(dp[t[i]]+1>maxi1){
			maxi2=maxi1;nd2=nd1;
			maxi1=dp[t[i]]+1;nd1=nr[t[i]]+1;
		}else if (dp[t[i]]+1>maxi2){
			maxi2=dp[t[i]]+1;nd2=nr[t[i]]+1;
		}
	}if(s[x]=='1')low=0;
	ans+=max(0,min(maxi1-1,maxi2+1)-low+1);
	vector<int> dpprmax(tot+2,0),dpsfmax(tot+2,0),nrprmin(tot+2,n),nrsfmin(tot+2,n);
	rep(i,1,tot){
		dpprmax[i]=max(dpprmax[i-1],dp[son[i-1]]+2);
		nrprmin[i]=min(nrprmin[i-1],nr[son[i-1]]+2);
	}	
	per(i,tot,1){
		dpsfmax[i]=max(dpsfmax[i+1],dp[son[i-1]]+2);
		nrsfmin[i]=min(nrsfmin[i+1],nr[son[i-1]]+2);
	}if(s[x]=='1')n1=0;
	rep(i,1,tot){
		dfs2(son[i-1],x,min(n1+1,min(nrprmin[i-1],nrsfmin[i+1])),max(max(dp1+1,dpprmax[i-1]),dpsfmax[i+1]));
	}
}
inline void addedge(int x,int y){
	ne[++num]=head[x];head[x]=num;t[num]=y;
	ne[++num]=head[y];head[y]=num;t[num]=x;
}
int main(){
	read(n);
	rep(i,1,n)head[i]=-1;
	rep(i,1,n-1){
		int x,y;read(x);read(y);
		addedge(x,y);
	}scanf("%s",s+1);
	dfs1(1,-1);
	dfs2(1,-1,n,0);
	ans++;
	printf("%lld\n",ans);
	return 0;
}

### Prompt

Your task is to create 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
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=200005;
int head[maxn],t[maxn<<1],ne[maxn<<1],num,n;
int dp[maxn],nr[maxn];
char s[maxn];
i64 ans=0;
inline void dfs1(int x,int f){
	dp[x]=0;nr[x]=n;if(s[x]=='1')nr[x]=0;
	forE(i,x)if(t[i]!=f){
		dfs1(t[i],x);
		dp[x]=max(dp[x],dp[t[i]]+1);
		nr[x]=min(nr[x],nr[t[i]]+1);
	}
}
inline void dfs2(int x,int f,int n1,int dp1){
	int maxi1=0,nd1=0,maxi2=0,nd2=0,tot=0,low=n;
	maxi1=dp1;nd1=n1;vector<int> son;
	if(nd1<n)low=min(low,maxi1);
	forE(i,x)if(t[i]!=f){
		tot++;son.pb(t[i]);
		if(nr[t[i]]!=n)low=min(low,dp[t[i]]+1);
		if(dp[t[i]]+1>maxi1){
			maxi2=maxi1;nd2=nd1;
			maxi1=dp[t[i]]+1;nd1=nr[t[i]]+1;
		}else if (dp[t[i]]+1>maxi2){
			maxi2=dp[t[i]]+1;nd2=nr[t[i]]+1;
		}
	}if(s[x]=='1')low=0;
	ans+=max(0,min(maxi1-1,maxi2+1)-low+1);
	vector<int> dpprmax(tot+2,0),dpsfmax(tot+2,0),nrprmin(tot+2,n),nrsfmin(tot+2,n);
	rep(i,1,tot){
		dpprmax[i]=max(dpprmax[i-1],dp[son[i-1]]+2);
		nrprmin[i]=min(nrprmin[i-1],nr[son[i-1]]+2);
	}	
	per(i,tot,1){
		dpsfmax[i]=max(dpsfmax[i+1],dp[son[i-1]]+2);
		nrsfmin[i]=min(nrsfmin[i+1],nr[son[i-1]]+2);
	}if(s[x]=='1')n1=0;
	rep(i,1,tot){
		dfs2(son[i-1],x,min(n1+1,min(nrprmin[i-1],nrsfmin[i+1])),max(max(dp1+1,dpprmax[i-1]),dpsfmax[i+1]));
	}
}
inline void addedge(int x,int y){
	ne[++num]=head[x];head[x]=num;t[num]=y;
	ne[++num]=head[y];head[y]=num;t[num]=x;
}
int main(){
	read(n);
	rep(i,1,n)head[i]=-1;
	rep(i,1,n-1){
		int x,y;read(x);read(y);
		addedge(x,y);
	}scanf("%s",s+1);
	dfs1(1,-1);
	dfs2(1,-1,n,0);
	ans++;
	printf("%lld\n",ans);
	return 0;
}

```