#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <class T>
inline void umin(T &x, T y) {
  x = x < y ? x : y;
}
template <class T>
inline void umax(T &x, T y) {
  x = x > y ? x : y;
}
inline unsigned int R() {
  static unsigned int seed = 416;
  return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 666666;
int n, f[N], g[N], sz[N];
vector<int> e[N];
long long res;
char s[N];
void dfs1(int u, int fa) {
  sz[u] = s[u] == '1';
  for (register int i = (0); i <= (((int)e[u].size()) - 1); i++)
    if (e[u][i] != fa)
      dfs1(e[u][i], u), umax(f[u], f[e[u][i]] + 1), sz[u] += sz[e[u][i]];
}
void dfs2(int u, int fa) {
  int mx = -1e9, semx = -1e9;
  for (register int i = (0); i <= (((int)e[u].size()) - 1); i++)
    if (e[u][i] != fa)
      if (f[e[u][i]] > mx) {
        semx = mx;
        mx = f[e[u][i]];
      } else if (f[e[u][i]] > semx)
        semx = f[e[u][i]];
  for (register int i = (0); i <= (((int)e[u].size()) - 1); i++)
    if (e[u][i] != fa)
      g[e[u][i]] = max(g[u] + 1, mx == f[e[u][i]] ? semx + 2 : mx + 2),
      dfs2(e[u][i], u);
}
int query(int *a, int n, int x) { return a[n] == x ? a[n - 1] : a[n]; }
void dfs(int u, int fa) {
  static int a[N];
  int len = 0;
  a[++len] = g[u];
  a[++len] = 0;
  for (register int i = (0); i <= (((int)e[u].size()) - 1); i++)
    if (e[u][i] != fa) a[++len] = f[e[u][i]] + 1;
  sort(a + 1, a + len + 1);
  if (s[u] == '1')
    res += a[len - 1] + 1;
  else {
    bool ok = 0;
    for (register int i = (0); i <= (((int)e[u].size()) - 1); i++)
      if (e[u][i] != fa) {
        if (sz[e[u][i]]) ok |= query(a, len, f[e[u][i]] + 1) >= f[e[u][i]] + 1;
      } else if (sz[1] - sz[u])
        ok |= query(a, len, g[u]) >= g[u];
    res += ok;
  }
  for (register int i = (0); i <= (((int)e[u].size()) - 1); i++)
    if (e[u][i] != fa) {
      int v = e[u][i];
      dfs(e[u][i], u);
      int x = g[v] - 1, y = f[v];
      bool ok = 0;
      if (y == min(x, y)) ok |= sz[v];
      if (x == min(x, y)) ok |= sz[1] - sz[v];
      res += ok;
    }
}
int main() {
  read(n);
  for (register int i = (1); i <= (n - 1); i++) {
    int u, v;
    read(u);
    read(v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  scanf("%s", s + 1);
  dfs1(1, 0);
  dfs2(1, 0);
  dfs(1, 0);
  cout << res;
  return 0;
}
