
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<lint,lint> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const int INF=5e8;
char s[200005];
int tot1;
int n;
vector<int> g[200005];
int size[200005],dist[200005];
int start[200005],fin[200005],cnt;
int msum[200005];
void dfs(int v,int p){
  size[v]=1;
  start[v]=cnt;
  msum[cnt+1]=msum[cnt]+(s[v]=='1'?1:0);
  ++cnt;
  dist[v]=0;
  for(auto to:g[v]){
    if(to==p) continue;
    dfs(to,v);
    size[v]+=size[to];
    chmax(dist[v],dist[to]+1);
  }
  fin[v]=cnt;
}
lint add=0;
int subt1(int v){
  return msum[fin[v]]-msum[start[v]];
}
int g2[200005];
int ub[200005],lb[200005];
void dfs3(int v,int p,int down){//...lim)
  pair<int,int> most,sec;
  most=sec=mp(-1,-1);
  most.sc=down;
  most.fr=p;
  sec.sc=0;
  for(auto to:g[v]){
    if(to==p) continue;
    int val=dist[to]+1;
    if(most.sc<val){
      sec=most;
      most=mp(to,val);
    }else if(sec.sc<val){
      sec=mp(to,val);
    }
  }
  ub[v]=sec.sc;
  lb[v]=INF;
  if(s[v]=='1') lb[v]=0;
  if(most.sc>sec.sc){
    g2[v]=most.fr;
  }

  if(~p){
    if(down-1<dist[v]){
      if(tot1-subt1(v)>0) ++add;
    }else if(down-1>dist[v]){
      if(subt1(v)>0) ++add;
    }else{
      ++add;
    }
    dump(v);dump(add);
  }
  for(auto to:g[v]){
    if(to==p) continue;
    int d;
    if(to==most.fr){
      d=sec.sc+1;
    }else{
      d=most.sc+1;
    }
    dfs3(to,v,d);
  }
}

int main(){
  cin>>n;
  REP(i,n-1){
    int a,b;scanf("%d%d",&a,&b);--a;--b;
    g[a].pb(b);
    g[b].pb(a);
  }
  scanf("%s",s);
  REP(i,n) if(s[i]=='1') ++tot1;

  dfs(0,-1);
  memset(g2,-1,sizeof(g2));
  dfs3(0,-1,0);

  priority_queue<pi,vector<pi>,greater<pi>>pq;
  REP(i,n){
    pq.push(mp(lb[i],i));
  }
  debug(g2,g2+n);
  while(!pq.empty()){
    pi cur=pq.top();pq.pop();
    if(cur.fr>n) continue;
    if(~g2[cur.sc] && lb[g2[cur.sc]]>ub[cur.sc]+1){
      lb[g2[cur.sc]]=ub[cur.sc]+1;
      pq.push(mp(lb[g2[cur.sc]],g2[cur.sc]));
    }
  }
  lint res=0;
  REP(i,n) res+=max(0,ub[i]-lb[i]+1);
  debug(lb,lb+n);
  debug(ub,ub+n);
  dump(add);
  res+=add;
    
  cout<<res<<endl;

  return 0;
}




### Prompt

Your challenge is to write 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,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<lint,lint> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const int INF=5e8;
char s[200005];
int tot1;
int n;
vector<int> g[200005];
int size[200005],dist[200005];
int start[200005],fin[200005],cnt;
int msum[200005];
void dfs(int v,int p){
  size[v]=1;
  start[v]=cnt;
  msum[cnt+1]=msum[cnt]+(s[v]=='1'?1:0);
  ++cnt;
  dist[v]=0;
  for(auto to:g[v]){
    if(to==p) continue;
    dfs(to,v);
    size[v]+=size[to];
    chmax(dist[v],dist[to]+1);
  }
  fin[v]=cnt;
}
lint add=0;
int subt1(int v){
  return msum[fin[v]]-msum[start[v]];
}
int g2[200005];
int ub[200005],lb[200005];
void dfs3(int v,int p,int down){//...lim)
  pair<int,int> most,sec;
  most=sec=mp(-1,-1);
  most.sc=down;
  most.fr=p;
  sec.sc=0;
  for(auto to:g[v]){
    if(to==p) continue;
    int val=dist[to]+1;
    if(most.sc<val){
      sec=most;
      most=mp(to,val);
    }else if(sec.sc<val){
      sec=mp(to,val);
    }
  }
  ub[v]=sec.sc;
  lb[v]=INF;
  if(s[v]=='1') lb[v]=0;
  if(most.sc>sec.sc){
    g2[v]=most.fr;
  }

  if(~p){
    if(down-1<dist[v]){
      if(tot1-subt1(v)>0) ++add;
    }else if(down-1>dist[v]){
      if(subt1(v)>0) ++add;
    }else{
      ++add;
    }
    dump(v);dump(add);
  }
  for(auto to:g[v]){
    if(to==p) continue;
    int d;
    if(to==most.fr){
      d=sec.sc+1;
    }else{
      d=most.sc+1;
    }
    dfs3(to,v,d);
  }
}

int main(){
  cin>>n;
  REP(i,n-1){
    int a,b;scanf("%d%d",&a,&b);--a;--b;
    g[a].pb(b);
    g[b].pb(a);
  }
  scanf("%s",s);
  REP(i,n) if(s[i]=='1') ++tot1;

  dfs(0,-1);
  memset(g2,-1,sizeof(g2));
  dfs3(0,-1,0);

  priority_queue<pi,vector<pi>,greater<pi>>pq;
  REP(i,n){
    pq.push(mp(lb[i],i));
  }
  debug(g2,g2+n);
  while(!pq.empty()){
    pi cur=pq.top();pq.pop();
    if(cur.fr>n) continue;
    if(~g2[cur.sc] && lb[g2[cur.sc]]>ub[cur.sc]+1){
      lb[g2[cur.sc]]=ub[cur.sc]+1;
      pq.push(mp(lb[g2[cur.sc]],g2[cur.sc]));
    }
  }
  lint res=0;
  REP(i,n) res+=max(0,ub[i]-lb[i]+1);
  debug(lb,lb+n);
  debug(ub,ub+n);
  dump(add);
  res+=add;
    
  cout<<res<<endl;

  return 0;
}




```