#include <bits/stdc++.h>
using namespace std;
int n;
char s[200005];
int f[200005], g[200005], high[200005], low[200005], out[200005], in[200005];
vector<int> v[200005];
void dfs(int x, int last) {
  if (s[x] == '1') in[x] = 1;
  for (int i = 0; i < (int)v[x].size(); i++)
    if (v[x][i] != last) {
      dfs(v[x][i], x);
      f[x] = max(f[v[x][i]] + 1, f[x]);
      in[x] |= in[v[x][i]];
    }
}
void dfs2(int x, int last) {
  int mx1 = 0, mx2 = 0, cut = 0;
  for (int i = 0; i < (int)v[x].size(); i++)
    if (v[x][i] != last) {
      if (f[v[x][i]] + 1 > mx1)
        mx2 = mx1, mx1 = f[v[x][i]] + 1;
      else if (f[v[x][i]] + 1 > mx2)
        mx2 = f[v[x][i]] + 1;
      cut += v[x][i];
    }
  for (int i = 0; i < (int)v[x].size(); i++)
    if (v[x][i] != last) {
      int y = v[x][i];
      if (f[y] + 1 == mx1)
        g[y] = max(g[x] + 1, mx2 + 1);
      else
        g[y] = max(g[x] + 1, mx1 + 1);
      out[y] = 1;
      if (cut - in[y] || s[x] == '1') out[y] = 1;
      dfs2(y, x);
    }
}
void dfs3(int x, int last) {
  int mx1 = g[x], mx2 = 0;
  for (int i = 0; i < (int)v[x].size(); i++)
    if (v[x][i] != last) {
      int y = v[x][i];
      if (f[y] + 1 > mx1)
        mx2 = mx1, mx1 = f[y] + 1;
      else if (f[y] + 1 > mx2)
        mx2 = f[y] + 1;
    }
  high[x] = min(mx2 + 1, mx1 - 1);
  if (s[x] == '1')
    low[x] = 0;
  else {
    low[x] = high[x] + 1;
    if (out[x]) low[x] = min(low[x], g[x]);
    for (int i = 0; i < (int)v[x].size(); i++)
      if (v[x][i] != last) {
        int y = v[x][i];
        if (in[y]) low[x] = min(low[x], f[y] + 1);
      }
  }
  for (int i = 0; i < (int)v[x].size(); i++)
    if (v[x][i] != last) {
      dfs3(v[x][i], x);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  scanf("%s", s + 1);
  dfs(1, 0);
  dfs2(1, 0);
  dfs3(1, 0);
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += high[i] - low[i] + 1;
  ans++;
  printf("%lld\n", ans);
  return 0;
}
