#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -f;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  x *= f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x) return;
  print(x / 10), putchar(x % 10 + 48);
}
void write(int x) {
  if (!x)
    putchar('0');
  else
    print(x);
  putchar('\n');
}
const int maxn = 5e5 + 10;
const int inf = 1e9;
const double eps = 1e-8;
char s[maxn];
int sz[maxn], d1[maxn], d2[maxn], d3[maxn], d4[maxn], n, head[maxn], tot,
    f[maxn];
struct edge {
  int to, nxt;
} e[maxn << 1];
void add(int u, int v) { e[++tot] = (edge){v, head[u]}, head[u] = tot; }
void ins(int u, int v) { add(u, v), add(v, u); }
void dfs(int x, int fa) {
  sz[x] = s[x] - '0', f[x] = fa;
  d3[x] = 1e9;
  for (int v, i = head[x]; i; i = e[i].nxt)
    if ((v = e[i].to) != fa) {
      dfs(v, x), sz[x] += sz[v];
      d1[x] = max(d1[x], d1[v] + 1);
      if (sz[v]) d3[x] = min(d3[x], d1[e[i].to] + 1);
    }
}
void dfs2(int x, int fa) {
  int first = 0, second = 0;
  if (fa) d4[x] = d2[x] - 1;
  for (int v, i = head[x]; i; i = e[i].nxt) {
    if ((v = e[i].to) == fa) continue;
    if (d1[v] > first)
      second = first, first = d1[v];
    else if (d1[v] > second)
      second = d1[v];
  }
  first++, second++;
  for (int v, i = head[x]; i; i = e[i].nxt) {
    if ((v = e[i].to) == fa) continue;
    if (d1[v] + 1 == first)
      d2[v] = max(d2[x], second) + 1;
    else
      d2[v] = max(d2[x], first) + 1;
    dfs2(e[i].to, x);
  }
}
int main() {
  read(n);
  for (int i = 1, x, y; i < n; i++) read(x), read(y), ins(x, y);
  scanf("%s", s + 1);
  dfs(1, 0), dfs2(1, 0);
  long long ans = 0;
  int mx, mn;
  for (int x = 1; x <= n; x++) {
    mx = max(d1[x], d2[x]) - 1;
    if (s[x] == '0')
      mn = min(d3[x], sz[1] == sz[x] ? (int)1e9 : d2[x]);
    else
      mn = 0;
    for (int i = head[x]; i; i = e[i].nxt)
      if (e[i].to == f[x])
        mx = min(mx, d1[x] + 1);
      else
        mx = min(mx, d4[e[i].to] + 1);
    if (mx >= mn) ans += (long long)mx - mn + 1;
  }
  printf("%lld\n", ans + 1ll);
  return 0;
}
