#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ret = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    ret = ret * 10 + c - 48;
    c = getchar();
  }
  if (f) return -ret;
  return ret;
}
const int N = 200005;
const int inf = 0x3f3f3f3f;
int n, top, head[N], ma1[N], ma2[N], d[N], size[N];
long long ans;
char s[N];
struct node {
  int too, Next;
} edge[N * 2];
void add(int a, int b) {
  edge[++top].too = b;
  edge[top].Next = head[a];
  head[a] = top;
}
void dfs1(int u, int fa) {
  if (s[u] == '1')
    d[u] = 0, size[u] = 1;
  else
    d[u] = inf;
  for (int i = head[u]; i; i = edge[i].Next) {
    int v = edge[i].too;
    if (v == fa) continue;
    dfs1(v, u);
    size[u] += size[v];
    if (ma1[v] + 1 > ma1[u]) {
      ma2[u] = ma1[u];
      ma1[u] = ma1[v] + 1;
    } else if (ma1[v] + 1 > ma2[u])
      ma2[u] = ma1[v] + 1;
    if (size[v]) d[u] = min(d[u], ma1[v] + 1);
  }
}
void dfs2(int u, int fa) {
  int R = min(ma2[u] + 1, ma1[u] - 1);
  cout << R << endl;
  if (d[u] <= R) ans += (long long)(R - d[u] + 1);
  for (int i = head[u]; i; i = edge[i].Next) {
    int v = edge[i].too;
    if (v == fa) continue;
    int xu = (ma1[v] + 1 == ma1[u] ? ma2[u] + 1 : ma1[u] + 1);
    if (xu > ma1[v]) {
      ma2[v] = ma1[v];
      ma1[v] = xu;
    } else if (xu > ma2[v])
      ma2[v] = xu;
    if (size[1] - size[v]) d[v] = min(d[v], xu);
    dfs2(v, u);
  }
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    add(x, y), add(y, x);
  }
  scanf("%s", s + 1);
  dfs1(1, 0);
  dfs2(1, 0);
  printf("%lld\n", ans + 1);
  return 0;
}
