#include <bits/stdc++.h>
using namespace std;
const int N = 400010, INF = 0x3f3f3f3f, MP = 20;
struct edge {
  int la, b;
} con[N << 1];
int tot, fir[N];
void add(int from, int to) {
  con[++tot] = (edge){fir[from], to};
  fir[from] = tot;
}
struct data {
  int dep, dis, id;
  bool operator<(const data& a) const {
    if (dep != a.dep) return dep < a.dep;
    if (dis != a.dis) return dis > a.dis;
    return id > a.id;
  }
};
data mxdep[N][2];
int n, hson[N], val[N], anc[N][MP], dep[N], cnt, vis[N];
char s[N];
long long ans;
void dfs(int pos, int fa) {
  dep[pos] = dep[fa] + 1;
  anc[pos][0] = fa;
  for (int i = 1; i < MP; ++i) {
    anc[pos][i] = anc[anc[pos][i - 1]][i - 1];
    if (!anc[pos][i]) break;
  }
  mxdep[pos][0] = (data){0, INF, 0};
  mxdep[pos][1] = (data){-INF, INF, 0};
  hson[pos] = 0;
  for (int i = fir[pos]; i; i = con[i].la) {
    if (con[i].b == fa) continue;
    dfs(con[i].b, pos);
    data tmp = mxdep[con[i].b][0];
    if (val[con[i].b]) tmp.dis = 0, tmp.id = con[i].b;
    if (mxdep[hson[pos]][0] < tmp || (!hson[pos])) hson[pos] = con[i].b;
    tmp.dep++;
    tmp.dis++;
    if (mxdep[pos][0] < tmp) {
      mxdep[pos][1] = mxdep[pos][0];
      mxdep[pos][0] = tmp;
    } else
      mxdep[pos][1] = max(mxdep[pos][1], tmp);
  }
}
void fsd(int pos, int fa) {
  for (int i = fir[pos]; i; i = con[i].la) {
    if (con[i].b == fa) continue;
    data tmp = (con[i].b == hson[pos] ? mxdep[pos][1] : mxdep[pos][0]);
    if (val[pos]) tmp.dis = 0, tmp.id = pos;
    tmp.dis++;
    tmp.dep++;
    if (mxdep[con[i].b][0] < tmp) {
      mxdep[con[i].b][1] = mxdep[con[i].b][0];
      mxdep[con[i].b][0] = tmp;
      hson[con[i].b] = pos;
    } else
      mxdep[con[i].b][1] = max(mxdep[con[i].b][1], tmp);
    fsd(con[i].b, pos);
  }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = MP - 1; i >= 0; --i)
    if (dep[anc[x][i]] >= dep[y]) x = anc[x][i];
  if (x == y) return x;
  for (int i = MP - 1; i >= 0; --i)
    if (anc[x][i] != anc[y][i]) x = anc[x][i], y = anc[y][i];
  return anc[x][0];
}
int la(int x, int k) {
  for (int i = MP - 1; i >= 0; --i)
    if ((k >> i) & 1) x = anc[x][i];
  return x;
}
int query(int x, int y, int l) {
  int z = lca(x, y);
  if (dep[x] - dep[z] >= l)
    return la(x, l);
  else
    return la(y, dep[x] + dep[y] - 2 * dep[z] - l);
}
int main() {
  int x, y;
  scanf("%d", &n);
  cnt = n;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &x, &y);
    ++cnt;
    add(x, cnt);
    add(cnt, x);
    add(y, cnt);
    add(cnt, y);
  }
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) val[i] = s[i] - '0';
  dfs(1, 0);
  fsd(1, 0);
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < 2; ++j) mxdep[i][j].dep >>= 1, mxdep[i][j].dis >>= 1;
  for (int i = 1; i <= n; ++i) {
    if (!val[i]) continue;
    ans += mxdep[i][1].dep + 1;
    if (mxdep[i][1].dep < mxdep[i][0].dep) {
      int v = mxdep[i][0].id;
      int tmp = min(mxdep[i][0].dep - mxdep[i][1].dep, mxdep[i][0].dis);
      ans += tmp - 1;
      int z = query(i, v, tmp);
      if (!vis[z]) ++ans, vis[z] = 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
