#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, sz[N], dep[N], u[N][2], v[N][3];
char s[N];
bool cir[N];
long long ans;
vector<int> g[N];
void upp(int x, int y) {
  if (!y) return;
  if (dep[y] - dep[x] > v[x][0]) {
    u[x][0] = y;
    v[x][0] = dep[y] - dep[x];
  } else if ((!u[x][1]) || dep[y] - dep[x] > v[x][1]) {
    u[x][1] = y;
    v[x][1] = dep[y] - dep[x];
  }
}
void dfs1(int x, int fr) {
  sz[x] = (s[x] == '1');
  u[x][0] = x;
  for (int y : g[x])
    if (y ^ fr) {
      dep[y] = dep[x] + 1;
      dfs1(y, x);
      sz[x] += sz[y];
      upp(x, u[y][0]);
    }
}
void dfs2(int x, int fr) {
  int val;
  if (sz[x]) {
    if (x == 1)
      val = v[x][0];
    else {
      if (u[x][0] == u[fr][0])
        val = max(v[fr][1], v[fr][2]);
      else
        val = max(v[fr][0], v[fr][2]);
      val = min(val, v[x][0] + 1);
    }
    ans += val;
  }
  for (int y : g[x])
    if (y ^ fr) {
      if (u[y][0] == u[x][0])
        v[y][2] = max(v[x][1], v[x][2]) + 1;
      else
        v[y][2] = max(v[x][0], v[x][2]) + 1;
      dfs2(y, x);
    }
}
int main() {
  int i, j, x, y;
  scanf("%d", &n);
  for (i = 1; i < n; ++i) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  scanf("%s", s + 1);
  dfs1(1, 0);
  dfs2(1, 0);
  printf("%lld", ans + sz[1]);
  return 0;
}
