#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') ch == '-' && (f = 0) || (ch = getchar());
  while (ch <= '9' && ch >= '0')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return f ? x : -x;
}
int to[200020 << 1], nxt[200020 << 1], head[200020], cnt;
void insert(int x, int y) {
  to[++cnt] = y;
  nxt[cnt] = head[x];
  head[x] = cnt;
  to[++cnt] = x;
  nxt[cnt] = head[y];
  head[y] = cnt;
}
char str[200020];
int chs[200020], tot, R[200020], L[200020], d1[200020], d2[200020], ans;
int fir_dfs(int x, int f) {
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] != f) {
      chs[x] += fir_dfs(to[i], x);
      int w = d1[to[i]] + 1;
      if (w > d1[x])
        d2[x] = d1[x], d1[x] = w;
      else if (w > d2[x])
        d2[x] = w;
    }
  }
  return chs[x];
}
int sec_dfs(int x, int f, int v) {
  R[x] = v > d1[x] ? d1[x] : max(v, d2[x]);
  L[x] = str[x] == '1' ? 0 : (tot != chs[x] ? v : (1 << 30));
  if (f) {
    if (d1[x] == v - 1)
      ++ans;
    else if (d1[x] < v - 1)
      ans += chs[x] > 0;
    else
      ans += chs[x] < tot;
  }
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] != f) {
      if (chs[to[i]]) L[x] = min(L[x], d1[to[i]] + 1);
      if (d1[to[i]] + 1 == d1[x])
        sec_dfs(to[i], x, max(v, d2[x]) + 1);
      else
        sec_dfs(to[i], x, max(v, d1[x]) + 1);
    }
  }
  return 0;
}
int main(int argc, char const *argv[]) {
  int n = read();
  for (int i = 1; i < n; ++i) {
    insert(read(), read());
  }
  scanf("%s", str + 1);
  for (int i = 1; i <= n; ++i) {
    tot += chs[i] = str[i] == '1';
  }
  fir_dfs(1, 0);
  sec_dfs(1, 0, 0);
  for (int i = 1; i <= n; ++i) {
    if (L[i] <= R[i]) {
      ans += R[i] - L[i] + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
