#include <bits/stdc++.h>
using namespace std;
struct data {
  int next, to;
  data(int next = 0, int to = 0) : next(next), to(to) {}
} edge[200005 << 1];
struct node {
  int maxd, state;
  node(int maxd = 0, int state = 0) : maxd(maxd), state(state) {}
  bool operator<(const node b) const { return maxd < b.maxd; }
};
int n;
int fa[200005], state[200005], maxd[200005], maxu[200005], se[200005],
    semaxd[200005];
int stated[200005], stateu[200005], target[200005], times[200005], deg[200005];
int head[200005], cnt;
long long ans = 0;
void connect(int u, int v) {
  edge[++cnt] = data(head[u], v);
  head[u] = cnt;
}
void DFS1(int u, int pre) {
  fa[u] = pre;
  times[u] = stated[u] = state[u];
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    ++deg[u];
    if (v == pre) continue;
    DFS1(v, u);
    stated[u] |= stated[v];
    if (stated[v]) {
      ++times[u];
      target[u] = v;
    }
    if (maxd[v] + 1 > maxd[u]) {
      semaxd[u] = maxd[u];
      maxd[u] = maxd[v] + 1;
    } else if (maxd[v] + 1 > semaxd[u])
      semaxd[u] = maxd[v] + 1;
  }
}
void DFS2(int u, int pre) {
  if (u != 1) {
    if (maxd[fa[u]] == maxd[u] + 1)
      maxu[u] = semaxd[fa[u]] + 1;
    else
      maxu[u] = maxd[fa[u]] + 1;
    maxu[u] = max(maxu[u], maxu[fa[u]] + 1);
    if ((stated[fa[u]] && times[fa[u]] > 1) ||
        (stated[fa[u]] && !stated[fa[u]]))
      stateu[u] = 1;
  }
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == pre) continue;
    DFS2(v, u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    connect(u, v);
    connect(v, u);
  }
  for (int i = 1; i <= n; ++i) scanf("%1d", &state[i]);
  DFS1(1, 0);
  DFS2(1, 0);
  for (int u = 1; u <= n; ++u) {
    if ((maxd[u] < maxu[u] - 1 && stated[u]) ||
        (maxd[u] > maxu[u] - 1 && stateu[u]) ||
        (maxd[u] == maxu[u] - 1 && (stateu[u] || stated[u]))) {
      ++ans;
    }
    int up = 0;
    if (maxu[u] > maxd[u])
      up = maxd[u];
    else
      up = max(maxu[u], semaxd[u]);
    if (state[u]) {
      ans += up + 1;
    } else {
      int down = stateu[u] ? maxu[u] : 0x3f3f3f3f;
      for (int i = head[u]; i; i = edge[i].next) {
        int v = edge[i].to;
        if (v == fa[u]) continue;
        if (stated[v]) down = min(down, maxd[v] + 1);
      }
      ans += max(0, up - down + 1);
    }
  }
  printf("%lld\n", ans);
}
