#include <bits/stdc++.h>
using namespace std;
int head[200005], ver[200005 * 2], nxt[2 * 200005], tot;
void add(int a, int b) {
  tot++;
  nxt[tot] = head[a];
  head[a] = tot;
  ver[tot] = b;
  return;
}
char s[200005];
int n, dis[200005], dis2[200005], g[200005], z[200005], zz[200005];
void up(int x, int ds, int yy) {
  if (ds >= dis[x]) {
    zz[x] = yy;
    dis2[x] = dis[x];
    dis[x] = ds;
  } else if (ds > dis2[x]) {
    dis2[x] = ds;
  }
}
int f1[200005], f2[200005];
void upp(int x, int ds, int yy) {
  if (ds <= f1[x]) {
    z[x] = yy;
    f2[x] = f1[x];
    f1[x] = ds;
  } else if (ds < f2[x]) {
    f2[x] = ds;
  }
}
void dfs(int x, int fa) {
  for (int i = head[x]; i; i = nxt[i]) {
    if (ver[i] == fa) continue;
    dfs(ver[i], x);
    up(x, dis[ver[i]] + 1, ver[i]);
    upp(x, f1[ver[i]] + 1, ver[i]);
  }
  if (f1[x] == 0x3f3f3f3f && s[x] == '1') upp(x, dis[x], zz[x]);
}
void dffs(int x, int fa) {
  for (int i = head[x]; i; i = nxt[i]) {
    if (ver[i] == fa) continue;
    int tp = dis[x] + 1;
    if (dis[ver[i]] + 1 == dis[x]) tp = dis2[x] + 1;
    int tmp = f1[x] + 1;
    if (z[x] == ver[i]) tmp = f2[x] + 1;
    upp(ver[i], tmp, x);
    if (s[x] == '1' && tmp >= 0x3f3f3f3f) upp(ver[i], tp, x);
    up(ver[i], tp, x);
    dffs(ver[i], x);
  }
}
int main() {
  scanf("%d", &n);
  int t1, t2;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &t1, &t2);
    add(t1, t2);
    add(t2, t1);
  }
  scanf("%s", s + 1);
  memset(f1, 0x3f, sizeof(f1));
  memset(f2, 0x3f, sizeof(f2));
  dfs(1, -1);
  dffs(1, -1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '0')
      ans += max(0, min(dis[i] - 1, dis2[i] + 1) - f1[i] + 1);
    else
      ans += max(0, min(dis[i] - 1, dis2[i] + 1) + 1);
  }
  cout << ans + 1 << endl;
  return 0;
}
