#include <bits/stdc++.h>
using namespace std;
inline void proc_status() {
  ifstream t("/proc/self/status");
  cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
       << endl;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline T read() {
  register T sum(0), fg(1);
  register char ch(getchar());
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fg = -1;
  for (; isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
  return sum * fg;
}
const int MAXN = (int)2e5;
int n;
vector<int> adj[MAXN + 5];
int type[MAXN + 5];
inline char safe_getchar() {
  register char ch(getchar());
  while (!isdigit(ch)) ch = getchar();
  return ch;
}
inline void input() {
  n = read<int>();
  for (int i = 1; i < n; ++i) {
    int u = read<int>(), v = read<int>();
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i) type[i] = safe_getchar() - '0';
}
int f[MAXN + 5], g[MAXN + 5], anc[MAXN + 5];
inline void dfs_f(int u, int fa) {
  anc[u] = fa;
  f[u] = 0;
  for (auto v : adj[u])
    if (v != fa) {
      dfs_f(v, u);
      chkmax(f[u], f[v] + 1);
    }
}
inline void dfs_g(int u, int fa) {
  int deg = ((int)(adj[u]).size()) - 1;
  static int pre[MAXN + 5], suf[MAXN + 5];
  for (int i = 0; i <= deg; ++i) {
    int v = adj[u][i];
    pre[i] = suf[i] = v == fa ? 0 : f[v] + 1;
  }
  for (int i = 1; i <= deg; ++i) chkmax(pre[i], pre[i - 1]);
  for (int i = deg - 1; i >= 0; --i) chkmax(suf[i], suf[i + 1]);
  for (int i = 0; i <= deg; ++i) {
    int v = adj[u][i];
    if (v != fa) {
      int res = g[u];
      if (i > 0) chkmax(res, pre[i - 1]);
      if (i < deg) chkmax(res, suf[i + 1]);
      chkmax(g[v], res + 1);
    }
  }
  for (auto v : adj[u])
    if (v != fa) dfs_g(v, u);
}
int p[MAXN + 5], q[MAXN + 5];
inline void dfs_p(int u, int fa) {
  for (auto v : adj[u])
    if (v != fa) {
      dfs_p(v, u);
      chkmin(p[u], p[v] + 1);
    }
}
inline void dfs_q(int u, int fa) {
  int deg = ((int)(adj[u]).size()) - 1;
  static int pre[MAXN + 5], suf[MAXN + 5];
  for (int i = 0; i <= deg; ++i) {
    int v = adj[u][i];
    pre[i] = suf[i] = v == fa ? INT_MAX / 2 : p[v] + 1;
    if (type[u]) chkmin(pre[i], f[v] + 1), chkmin(suf[i], f[v] + 1);
  }
  for (int i = 1; i <= deg; ++i) chkmin(pre[i], pre[i - 1]);
  for (int i = deg - 1; i >= 0; --i) chkmin(suf[i], suf[i + 1]);
  for (int i = 0; i <= deg; ++i) {
    int v = adj[u][i];
    if (v != fa) {
      int res = q[u];
      if (i > 0) chkmin(res, pre[i - 1]);
      if (i < deg) chkmin(res, suf[i + 1]);
      chkmin(q[v], res + 1);
    }
  }
  for (auto v : adj[u])
    if (v != fa) dfs_q(v, u);
}
inline void solve() {
  dfs_f(1, 0);
  dfs_g(1, 0);
  for (int i = 1; i <= n; ++i) {
    p[i] = type[i] ? f[i] : INT_MAX / 2;
    q[i] = type[i] ? g[i] : INT_MAX / 2;
  }
  dfs_p(1, 0);
  q[1] = INT_MAX / 2, dfs_q(1, 0);
  long long ans = 1;
  for (int u = 1; u <= n; ++u) {
    int l = type[u] ? 0 : min(p[u], q[u]), r = max(f[u], g[u]) - 1;
    for (auto v : adj[u]) {
      if (v == anc[u])
        chkmin(r, f[u] + 1);
      else
        chkmin(r, g[v]);
    }
    ans += max(0, r - l + 1);
  }
  printf("%lld\n", ans);
}
int main() {
  input();
  solve();
  return 0;
}
