#include <bits/stdc++.h>
using namespace std;
int n, M = 0, fst[666666], vb[666666], nxt[666666];
void ad_de(int a, int b) {
  ++M;
  nxt[M] = fst[a];
  fst[a] = M;
  vb[M] = b;
}
void adde(int a, int b) {
  ad_de(a, b);
  ad_de(b, a);
}
int md[666666], mu[666666], fa[666666];
void dfs(int x, int f = 0) {
  fa[x] = f;
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f) {
      dfs(b, x);
      md[x] = max(md[x], md[b]);
    }
  ++md[x];
}
void dfs2(int x, int f = 0) {
  int cm = mu[x] + 1;
  vector<int> vs;
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f) vs.push_back(b);
  for (int i = 0; i < vs.size(); ++i) {
    int v = vs[i];
    mu[v] = max(mu[v], cm);
    cm = max(cm, md[v] + 2);
  }
  cm = mu[x] + 1;
  for (int i = int(vs.size()) - 1; i >= 0; --i) {
    int v = vs[i];
    mu[v] = max(mu[v], cm);
    cm = max(cm, md[v] + 2);
  }
  vs.clear();
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f) dfs2(b, x);
}
int dd[666666];
void doit(int x) {
  vector<int> v;
  v.push_back(mu[x] - 1);
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != fa[x]) v.push_back(md[b]);
  sort(v.begin(), v.end());
  int p = v[v.size() - 1] - 1;
  if (v.size() > 1)
    p = min(p, v[v.size() - 2] + 1);
  else
    p = min(p, 1);
  dd[x] = p;
}
int d[666666], u[666666];
char c[666666];
void dfs3(int x, int f = 0) {
  int mx = 0;
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f) mx = max(mx, md[b]), dfs3(b, x), u[x] = min(u[x], u[b] + 1);
  if (c[x] == '1') u[x] = min(u[x], mx);
}
void dfs4(int x, int f = 0) {
  vector<int> vs;
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f) vs.push_back(b);
  if (c[x] == '1') {
    int cm = mu[x] - 1;
    for (int i = 0; i < vs.size(); ++i) {
      int v = vs[i];
      d[v] = cm;
      cm = max(cm, md[v]);
    }
    cm = mu[x] - 1;
    for (int i = int(vs.size()) - 1; i >= 0; --i) {
      int v = vs[i];
      d[v] = max(d[v], cm) + 1;
      cm = max(cm, md[v]);
    }
  }
  int cm = 1e9;
  for (int i = 0; i < vs.size(); ++i) {
    int v = vs[i];
    d[v] = min(cm, d[v]);
    cm = min(cm, u[v] + 2);
  }
  cm = 1e9;
  for (int i = int(vs.size()) - 1; i >= 0; --i) {
    int v = vs[i];
    d[v] = min(d[v], cm);
    cm = min(cm, u[v] + 2);
  }
  vs.clear();
  int mx = 0;
  for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
    if (b != f) d[b] = min(d[b], d[x] + 1), dfs4(b, x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1, a, b; i < n; ++i) scanf("%d%d", &a, &b), adde(a, b);
  dfs(1);
  mu[1] = 1;
  dfs2(1);
  scanf("%s", c + 1);
  memset(d, 127 / 3, sizeof d);
  memset(u, 127 / 3, sizeof u);
  dfs3(1);
  dfs4(1);
  long long ans = 1;
  for (int i = 1; i <= n; ++i) {
    int lo = min(d[i], u[i]);
    if (c[i] == '1') lo = 0;
    doit(i);
    ans += max(dd[i] - lo + 1, 0);
  }
  printf("%lld\n", ans);
}
