
#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;
}



