#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
int f[N], MaxD[N], FaD[N], Lim[N], Min[N], Max[N];
int MaxD2[N], FaD2[N];
vector<int> e[N];
void dfs(int x, int pre) {
  MaxD[x] = 0;
  MaxD2[x] = FaD2[x] = 1e9;
  for (auto y : e[x])
    if (y != pre) {
      dfs(y, x);
      MaxD[x] = max(MaxD[x], MaxD[y] + 1);
      MaxD2[x] = min(MaxD2[x], MaxD2[y] + 1);
    }
  if (f[x]) MaxD2[x] = min(MaxD2[x], MaxD[x]);
}
multiset<int> S;
long long ans = 0;
void getlim(int x, int pre) {
  Lim[x] = max(FaD[x], MaxD[x]);
  S.clear();
  S.insert(FaD[x]);
  for (auto y : e[x])
    if (y != pre) S.insert(MaxD[y] + 1);
  for (auto y : e[x])
    if (y != pre) {
      S.erase(S.find(MaxD[y] + 1));
      FaD[y] = (*--S.end()) + 1;
      S.insert(MaxD[y] + 1);
    }
  S.clear();
  if (f[x]) FaD2[x] = min(FaD[x], FaD2[x]);
  if (x != 1) S.insert(FaD2[x]);
  for (auto y : e[x])
    if (y != pre)
      S.insert(f[x] ? min(MaxD2[y] + 1, MaxD[y] + 1) : (MaxD2[y] + 1));
  for (auto y : e[x])
    if (y != pre) {
      S.erase(S.find(f[x] ? min(MaxD2[y] + 1, MaxD[y] + 1) : (MaxD2[y] + 1)));
      FaD2[y] = (*S.begin()) + 1;
      S.insert(f[x] ? min(MaxD2[y] + 1, MaxD[y] + 1) : (MaxD2[y] + 1));
    }
  for (auto y : e[x])
    if (y != pre) getlim(y, x);
}
void solve(int x, int pre) {
  for (auto y : e[x])
    if (y != pre) {
      solve(y, x);
      Min[y] = min(Min[y], MaxD[y] + 1);
      Min[x] = min(Min[x], FaD[y]);
      if (f[x] && !f[y]) Max[y] = min(Max[y], FaD2[y]);
      if (f[y] && !f[x]) Max[x] = min(Max[x], MaxD2[y] + 1);
    }
}
int main() {
  scanf("%d", &n);
  ans = 1;
  for (int i = 1; i <= n; i++) e[i].clear();
  for (int i = 1, a, b; i < n; i++) {
    scanf("%d%d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
  int tag = 0;
  for (int i = 1; i <= n; i++) scanf("%1d", &f[i]), tag |= f[i];
  if (!tag) return puts("0"), 0;
  dfs(1, 0);
  getlim(1, 0);
  for (int i = 1; i <= n; i++) Min[i] = Lim[i] - 1, Max[i] = f[i] ? 0 : 1e9;
  solve(1, 0);
  for (int i = 1; i <= n; i++) ans += max(Min[i] - Max[i] + 1, 0);
  printf("%lld", ans);
  return 0;
}
