#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, INF = 1e9;
int n, u, v, i, j, lim, bot;
long long ans;
char s[N];
int deep[N * 2], key[N * 2], far[N];
int En, size[N], fst[N], nxt[N * 2], to[N * 2];
void add(int u, int v) {
  En++;
  nxt[En] = fst[u];
  fst[u] = En;
  to[En] = v;
}
int add(int x) {
  if (x == INF) return x;
  return x + 1;
}
void dfs1(int x, int fa) {
  int j;
  for (j = fst[x]; j; j = nxt[j])
    if (to[j] != fa) {
      dfs1(to[j], x);
      key[j] = size[to[j]];
      far[x] = max(far[to[j]] + 1, far[x]);
      size[x] += size[to[j]];
    }
  if (s[x] == '1') size[x]++;
}
void updata(int dt, int &fs, int &sc) {
  if (dt > fs)
    sc = fs, fs = dt;
  else if (dt > sc)
    sc = dt;
}
int get(int x, int fs, int sc) {
  if (fs == sc) return fs;
  if (x == fs) return sc;
  return fs;
}
void dfs2(int x, int fa, int abv, int edge) {
  int j, v, fs = abv + 1, sc = 0, _abv;
  deep[edge ^ 1] = abv;
  far[x] = max(far[x], abv + 1);
  for (j = fst[x]; j; j = nxt[j])
    if (to[j] != fa) {
      v = to[j];
      updata(far[v] + 1, fs, sc);
    }
  for (j = fst[x]; j; j = nxt[j])
    if (to[j] != fa) {
      v = to[j];
      _abv = get(far[v] + 1, fs, sc);
      key[j ^ 1] = size[1] - size[v];
      deep[j] = far[v];
      dfs2(v, x, _abv, j);
    }
}
int main() {
  scanf("%d", &n);
  En = 1;
  for (i = 1; i <= n - 1; i++) {
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  scanf("%s", s + 1);
  dfs1(1, 1);
  dfs2(1, 1, -1, 0);
  for (i = 1; i <= n; i++) {
    lim = far[i] - 1;
    for (j = fst[i]; j; j = nxt[j])
      if (key[j]) lim = min(lim, deep[j ^ 1] + 1);
    if (s[i] == '1')
      bot = 0;
    else {
      bot = INF;
      for (j = fst[i]; j; j = nxt[j])
        if (key[j] > 0) bot = min(bot, deep[j] + 1);
    }
    if (lim >= bot) ans += lim - bot + 1;
  }
  printf("%lld\n", ans + 1);
  return 0;
}
