#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200005;
class Edge {
 public:
  int nxt, to;
} e[MAX_N << 1];
int head[MAX_N], cnt;
void addedge(int u, int v) {
  e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
  e[++cnt] = (Edge){head[v], u}, head[v] = cnt;
}
int N;
char S[MAX_N];
int mx[MAX_N], smx[MAX_N], val[MAX_N];
void update(int x, int v) {
  if (mx[x] <= v)
    smx[x] = mx[x], mx[x] = v;
  else if (smx[x] < v)
    smx[x] = v;
}
void dfs1(int u, int v) {
  mx[u] = 0;
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != v) {
      dfs1(e[i].to, u);
      update(u, mx[e[i].to] + 1);
    }
  val[u] = mx[u] + 2;
}
void dfs2(int u, int v) {
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != v) {
      int d;
      if (mx[u] == mx[e[i].to] + 1) {
        update(e[i].to, smx[u] + 1);
        val[e[i].to] = min(val[e[i].to], smx[u] + 1);
      } else {
        update(e[i].to, mx[u] + 1);
        val[e[i].to] = min(val[e[i].to], mx[u] + 1);
      }
      dfs2(e[i].to, u);
    }
}
int main() {
  scanf("%d", &N);
  for (int i = 1, u, v; i < N; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
  }
  scanf("%s", S + 1);
  for (int i = 1; i <= N; ++i) S[i] = S[i] - '0';
  dfs1(1, 0);
  dfs2(1, 0);
  long long res = 0;
  for (int i = 2; i <= N; ++i) res += val[i];
  res += mx[1] + 1;
  printf("%lld\n", res);
  return 0;
}
