#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "sz = " << vc.size() << endl << "[";
  for (const T& v : vc) o << v << ",";
  o << "]";
  return o;
}
int N;
const int MN = 400000;
string s;
using Data = pair<int, int>;
using SubData = pair<int, int>;
vector<int> G[MN];
int par[MN];
Data dp[MN];
SubData dp_nottermed[MN];
Data up[MN];
Data DP[MN];
vector<SubData> ls, rs;
SubData init(0, 0);
SubData merge(SubData val, Data v) {
  return SubData(max(val.first, v.first + 1), max(val.second, v.second));
}
SubData merge2(SubData x, SubData y) {
  return SubData(max(x.first, y.first), max(x.second, y.second));
}
Data term(SubData val, int v) {
  return Data(val.first, val.second | (s[v] == '1'));
}
void dfs(int v, int p = -1) {
  par[v] = p;
  SubData val = init;
  for (int u : G[v])
    if (u != p) {
      dfs(u, v);
      val = merge(val, dp[u]);
    }
  dp_nottermed[v] = val;
  dp[v] = term(val, v);
}
void ufs(int v, int p = -1) {
  vector<int> ch;
  for (int u : G[v])
    if (u != p) ch.push_back(u);
  int K = ch.size();
  ls.resize(K + 1);
  rs.resize(K + 1);
  ls[0] = init;
  rs[0] = init;
  for (int i = 0; i < (int)(K); i++) {
    ls[i + 1] = merge(ls[i], dp[ch[i]]);
    rs[i + 1] = merge(rs[i], dp[ch[K - 1 - i]]);
  }
  for (int i = 0; i < (int)(K); i++) {
    int u = ch[i];
    SubData val = merge2(ls[i], rs[K - 1 - i]);
    if (p >= 0) val = merge(val, up[v]);
    up[u] = term(val, u);
  }
  for (int i = 0; i < (int)(K); i++) ufs(ch[i], v);
}
void calcDP(int N, int r = 0) {
  dfs(r);
  ufs(r);
  for (int v = 0; v < (int)(N); v++) {
    SubData val = dp_nottermed[v];
    if (v != r) val = merge(val, up[v]);
    DP[v] = term(val, v);
  }
}
int inf = 1e9;
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < (int)(N - 1); i++) {
    int e = N + i;
    int x, y;
    scanf("%d %d", &x, &y);
    x--, y--;
    G[x].push_back(e);
    G[e].push_back(x);
    G[y].push_back(e);
    G[e].push_back(y);
  }
  cin >> s;
  s += string(N - 1, '0');
  calcDP(2 * N - 1);
  long long ans = 0;
  for (int r = 0; r < (int)(2 * N - 1); r++) {
    int mx = -inf, mx2 = -inf;
    int hasmin = inf;
    for (int u : G[r]) {
      Data p = (u == par[r] ? up[r] : dp[u]);
      int d = p.first + 1;
      int has = p.second;
      if (has) hasmin = min(hasmin, d);
      if (mx < d) {
        mx2 = mx;
        mx = d;
      } else if (mx2 < d) {
        mx2 = d;
      }
    }
    int tmp = 0;
    if (r < N) {
      if (mx2 == -inf) mx2 = 0;
      assert(mx2 % 2 == 0);
      assert(hasmin % 2 == 0);
      int x = mx2 / 2;
      int y = hasmin / 2;
      if (s[r] == '1') y = 0;
      tmp = max(0, x - y + 1);
    } else {
      assert(mx2 != -inf);
      assert(mx2 % 2 == 1);
      assert(hasmin % 2 == 1);
      int x = mx2 / 2;
      int y = hasmin / 2;
      tmp = max(0, x - y + 1);
    }
    ans += tmp;
  }
  cout << ans << endl;
}
