#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9, INF = 0x3f3f3f3f;
int f[N], g[N], n, nf[N], ng[N], d[N];
long long ans;
bool is[N], nis[N];
char s[N];
vector<int> V[N];
void Gx(int &f, int &g, int _f) {
  if (_f >= f) {
    g = f;
    f = _f;
  } else if (_f >= g)
    g = _f;
}
void Dfs(int u, int fa) {
  if (s[u] == '1') is[u] = 1;
  for (auto v : V[u])
    if (v != fa) {
      Dfs(v, u);
      is[u] |= is[v];
      if (is[v] && f[v] < d[u]) d[u] = f[v];
      Gx(f[u], g[u], f[v]);
    }
  if (f[u] < 0) f[u] = 0;
  ++f[u];
  ++g[u];
  ++d[u];
}
void Dfs2(int u, int fa) {
  if (nis[u] && nf[u] < 0) nf[u] = 2;
  Gx(f[u], g[u], nf[u]);
  if (nis[u] && nf[u] < d[u]) d[u] = nf[u];
  nis[u] |= is[u];
  int a = nf[u], b = -INF;
  bool o = nis[u];
  for (auto v : V[u])
    if (v != fa) {
      Gx(nf[v], ng[v], a + 1);
      nis[v] |= o;
      Gx(a, b, f[v] + 1);
      if (is[v]) o |= 1;
    }
  a = b = -INF;
  o = 0;
  for (int i = V[u].size() - 1, v; ~i; --i)
    if ((v = V[u][i]) != fa) {
      Gx(nf[v], ng[v], a + 1);
      nis[v] |= o;
      Gx(a, b, f[v] + 1);
      if (is[v]) o |= 1;
    }
  for (auto v : V[u])
    if (v != fa) {
      Dfs2(v, u);
    }
}
int main() {
  memset(g, 0xc0, sizeof g);
  memset(d, 0x3f, sizeof d);
  memset(f, 0xc0, sizeof f);
  memset(nf, 0xc0, sizeof nf);
  memset(ng, 0xc0, sizeof ng);
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; ++i)
    scanf("%d%d", &u, &v), V[u].emplace_back(v), V[v].emplace_back(u);
  scanf("%s", s + 1);
  if (n == 1) return printf("%d\n", s[1] == '1'), 0;
  if (n == 2)
    return printf("%d\n",
                  (s[1] == '1') + (s[2] == '1') + (s[1] == '1' || s[2] == '1')),
           0;
  Dfs(1, 0);
  Dfs2(1, 0);
  for (int i = 1; i <= n; ++i) {
    if (V[i].size() == 1) {
      if (s[i] == '1') ans += 2;
      continue;
    }
    if (g[i] < 0) g[i] = INF;
    if (f[i] < 0) f[i] = INF;
    if (s[i] != '1') {
      if (!is[i])
        continue;
      else
        ans -= d[i] - 1;
    }
    ans += min(g[i] + 1, f[i] - 1);
  }
  printf("%lld\n", ans + bool(ans));
  return 0;
}
