#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - 48;
    ch = getchar();
  }
  return x * f;
}
template <typename T>
inline bool Max(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool Min(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
const int N = 2e5 + 7, inf = 1e9 + 7;
int n, edc;
int head[N], L[N], R[N], mi[N][2], mx[N][2], g[N], has[N], cnt[N], fh[N];
long long ans;
char s[N];
struct edge {
  int lst, to;
} e[N << 1];
void Add(int a, int b) {
  e[++edc] = (edge){head[a], b}, head[a] = edc;
  e[++edc] = (edge){head[b], a}, head[b] = edc;
}
void dfs1(int u, int fa) {
  mi[u][0] = mi[u][1] = inf;
  if (s[u] == '1') has[u] = 1, cnt[u] = 1;
  for (int i = head[u], v = e[i].to; i; i = e[i].lst, v = e[i].to)
    if (v ^ fa) {
      dfs1(v, u);
      has[u] |= has[v];
      cnt[u] += has[v];
      if (mx[v][0] + 1 < mi[u][0])
        mi[u][1] = mi[u][0], mi[u][0] = mx[v][0] + 1;
      else
        Min(mi[u][1], mx[v][0] + 1);
      if (mx[v][0] + 1 > mx[u][0])
        mx[u][1] = mx[u][0], mx[u][0] = mx[v][0] + 1;
      else
        Max(mx[u][1], mx[v][0] + 1);
    }
}
void dfs2(int u, int fa) {
  for (int i = head[u], v = e[i].to; i; i = e[i].lst, v = e[i].to)
    if (v ^ fa) {
      g[v] = max(g[u], mx[v][0] + 1 == mx[u][0] ? mx[u][1] : mx[u][0]) + 1;
      fh[v] = fh[u] | (has[v] ? cnt[u] > 1 : cnt[u] > 0);
      dfs2(v, u);
    }
  ans += (g[u] <= mx[u][0] && fh[u]) || (mx[u][0] <= g[u] && has[u]);
  if (s[u] == '1') {
    ans += (g[u] >= mx[u][0] ? mx[u][0] : max(mx[u][1], g[u])) + 1;
  } else {
    int R = g[u] >= mx[u][0] ? mx[u][0] : max(mx[u][1], g[u]);
    int L = fh[u] ? g[u] : inf;
    for (int i = head[u], v = e[i].to; i; i = e[i].lst, v = e[i].to)
      if (v ^ fa && has[v]) Min(L, mx[v][0] + 1);
    if (L <= R) ans += R - L + 1;
  }
}
int main() {
  n = gi();
  for (int i = 1; i <= n - 1; ++i) Add(gi(), gi());
  scanf("%s", s + 1);
  dfs1(1, 0);
  dfs2(1, 0);
  printf("%lld\n", ans);
  return 0;
}
