#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int M = 4e5 + 5;
long long ans = 1;
int si[N], vm[N], md[N], sd[N], mdep[N];
int n, now, cnt, v[M], vi[N], nex[M], head[N];
void addedges(int x, int y) {
  nex[++now] = head[x];
  head[x] = now, v[now] = y;
}
void dfs(int x, int fa) {
  if (vi[x]) si[x] = 1;
  for (int i = head[x]; i; i = nex[i])
    if (v[i] != fa) {
      dfs(v[i], x);
      si[x] += si[v[i]];
      if (md[v[i]] + 1 > md[x])
        vm[x] = v[i], sd[x] = md[x], md[x] = md[v[i]] + 1;
      else
        sd[x] = max(sd[x], md[v[i]] + 1);
    }
}
void Dfs(int x, int fa) {
  int dep = md[fa] + 1;
  if (vm[fa] == x) dep = sd[fa] + 1;
  if (dep > md[x])
    vm[x] = fa, sd[x] = md[x], md[x] = dep;
  else
    sd[x] = max(sd[x], dep);
  if (vi[x])
    ans += min(sd[x] + 1, md[x] - 1) + 1;
  else {
    int se = n;
    for (int i = head[x]; i; i = nex[i])
      if (v[i] != fa && si[v[i]]) se = min(se, md[v[i]] + 1);
    if (si[x] != cnt) se = min(se, dep);
    int r = min(sd[x] + 1, md[x] - 1);
    if (r >= se) ans += r - se + 1;
  }
  for (int i = head[x]; i; i = nex[i])
    if (v[i] != fa) Dfs(v[i], x);
}
int main() {
  scanf("%d", &n);
  for (int x, y, i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    addedges(x, y);
    addedges(y, x);
  }
  for (int i = 1; i <= n; i++) {
    char ch = getchar();
    while (ch != '0' && ch != '1') ch = getchar();
    if (ch == '1') ++cnt;
    vi[i] = ch ^ 48;
  }
  dfs(1, 0), Dfs(1, 0);
  printf("%lld\n", ans);
  return 0;
}
