#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 200100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
const int inf=1e9;
struct Line{int v,next;}e[MAX<<1];
int h[MAX],cnt=1,dg[MAX];
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;++dg[u];}
int n,c[MAX],fa[MAX],sz[MAX];ll ans;
int S[MAX],top;
char s[MAX];
int d1[MAX];//子树中距离最远的一个点
int d2[MAX];//同上，可以从父亲转移
int d3[MAX];//子树中有经过至少一个黑点的最远点
int d4[MAX];//同上，可以从父亲转移
int d5[MAX];
int d6[MAX];//每一个点的下界
void dfs1(int u,int ff)
{
	fa[u]=ff;sz[u]=c[u];
	if((u!=1&&dg[u]==1)||(u==1&&!dg[u]))//leaves
	{
		d1[u]=0;d3[u]=c[u]?0:inf;
		return;
	}
	int mx=0,mx2=inf;
	for(int i=h[u];i;i=e[i].next)
	{
		int v=e[i].v;if(v==ff)continue;
		dfs1(v,u);sz[u]+=sz[v];
		mx=max(mx,d1[v]);
		if(d3[v]<inf)mx2=min(mx2,d1[v]);
	}
	d1[u]=mx+1;d3[u]=mx2+1;
	if(c[u])d3[u]=min(d3[u],d1[u]);
}
void dfs2(int u,int ff)
{
	d2[u]=max(d2[u],(ff!=0)+d2[ff]);
	if(ff)d5[u]=max(d5[u],d2[u]-1);
	top=0;for(int i=h[u];i;i=e[i].next)if(e[i].v!=ff)S[++top]=e[i].v;
	for(int i=1,mx=-1;i<=top;++i)//前缀其他儿子转移一下
	{
		int v=S[i];
		d2[v]=max(d2[v],mx+2);
		mx=max(mx,d1[v]);
	}
	for(int i=top,mx=-1;i>=1;--i)//后缀其他儿子转移一下
	{
		int v=S[i];
		d2[v]=max(d2[v],mx+2);
		mx=max(mx,d1[v]);
	}
	for(int i=h[u];i;i=e[i].next)
		if(e[i].v!=ff)dfs2(e[i].v,u);
}
int main()
{
	n=read();
	for(int i=1;i<n;++i)
	{
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
	scanf("%s",s+1);int tot=0;
	for(int i=1;i<=n;++i)tot+=(c[i]=s[i]-48);
	if(!tot){puts("0");return 0;}
	memset(d3,63,sizeof(d3));memset(d4,63,sizeof(d4));
	dfs1(1,0);dfs2(1,0);
	for(int i=1;i<=n;++i)
	{
		if(c[i])d6[i]=0;
		else d6[i]=min(d3[i],(sz[i]==sz[1])?inf:d2[i]);
		int u=max(d1[i],d2[i])-1;
		for(int j=h[i];j;j=e[j].next)
		{
			int v=e[j].v;
			if(v==fa[i])u=min(u,d1[i]+1);
			else u=min(u,d5[v]+1);
		}
		if(u>=d6[i])ans+=u-d6[i]+1;
	}
	cout<<ans+1<<endl;
	return 0;
}

### 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<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 200100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
const int inf=1e9;
struct Line{int v,next;}e[MAX<<1];
int h[MAX],cnt=1,dg[MAX];
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;++dg[u];}
int n,c[MAX],fa[MAX],sz[MAX];ll ans;
int S[MAX],top;
char s[MAX];
int d1[MAX];//子树中距离最远的一个点
int d2[MAX];//同上，可以从父亲转移
int d3[MAX];//子树中有经过至少一个黑点的最远点
int d4[MAX];//同上，可以从父亲转移
int d5[MAX];
int d6[MAX];//每一个点的下界
void dfs1(int u,int ff)
{
	fa[u]=ff;sz[u]=c[u];
	if((u!=1&&dg[u]==1)||(u==1&&!dg[u]))//leaves
	{
		d1[u]=0;d3[u]=c[u]?0:inf;
		return;
	}
	int mx=0,mx2=inf;
	for(int i=h[u];i;i=e[i].next)
	{
		int v=e[i].v;if(v==ff)continue;
		dfs1(v,u);sz[u]+=sz[v];
		mx=max(mx,d1[v]);
		if(d3[v]<inf)mx2=min(mx2,d1[v]);
	}
	d1[u]=mx+1;d3[u]=mx2+1;
	if(c[u])d3[u]=min(d3[u],d1[u]);
}
void dfs2(int u,int ff)
{
	d2[u]=max(d2[u],(ff!=0)+d2[ff]);
	if(ff)d5[u]=max(d5[u],d2[u]-1);
	top=0;for(int i=h[u];i;i=e[i].next)if(e[i].v!=ff)S[++top]=e[i].v;
	for(int i=1,mx=-1;i<=top;++i)//前缀其他儿子转移一下
	{
		int v=S[i];
		d2[v]=max(d2[v],mx+2);
		mx=max(mx,d1[v]);
	}
	for(int i=top,mx=-1;i>=1;--i)//后缀其他儿子转移一下
	{
		int v=S[i];
		d2[v]=max(d2[v],mx+2);
		mx=max(mx,d1[v]);
	}
	for(int i=h[u];i;i=e[i].next)
		if(e[i].v!=ff)dfs2(e[i].v,u);
}
int main()
{
	n=read();
	for(int i=1;i<n;++i)
	{
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
	scanf("%s",s+1);int tot=0;
	for(int i=1;i<=n;++i)tot+=(c[i]=s[i]-48);
	if(!tot){puts("0");return 0;}
	memset(d3,63,sizeof(d3));memset(d4,63,sizeof(d4));
	dfs1(1,0);dfs2(1,0);
	for(int i=1;i<=n;++i)
	{
		if(c[i])d6[i]=0;
		else d6[i]=min(d3[i],(sz[i]==sz[1])?inf:d2[i]);
		int u=max(d1[i],d2[i])-1;
		for(int j=h[i];j;j=e[j].next)
		{
			int v=e[j].v;
			if(v==fa[i])u=min(u,d1[i]+1);
			else u=min(u,d5[v]+1);
		}
		if(u>=d6[i])ans+=u-d6[i]+1;
	}
	cout<<ans+1<<endl;
	return 0;
}

```