#include <bits/stdc++.h>
int ri() {
  int n;
  scanf("%d", &n);
  return n;
}
std::vector<std::vector<int> > hen;
std::vector<bool> enabled;
int all_enabled;
std::vector<int> height, depth, enabled_sum;
void dfs0(int i, int prev) {
  if (prev != -1) hen[i].erase(std::find(hen[i].begin(), hen[i].end(), prev));
  enabled_sum[i] = enabled[i];
  for (auto j : hen[i]) {
    depth[j] = depth[i] + 1;
    dfs0(j, i);
    height[i] = std::max(height[i], height[j] + 1);
    enabled_sum[i] += enabled_sum[j];
  }
}
int64_t res = 1;
std::vector<int> max_depth, min_depth;
void dfs1(int i, int prev, int prev_depth) {
  if (prev != -1 && enabled[prev])
    min_depth[i] = std::min(min_depth[i], depth[prev] + prev_depth - 1);
  if (hen[i].size() && depth[i] >= min_depth[i]) res++;
  int m = hen[i].size();
  if (m) {
    std::vector<std::pair<int, int> > subtrees;
    if (prev != -1)
      subtrees.push_back({prev_depth, all_enabled - enabled_sum[i]});
    int left[m], right[m];
    left[0] = 0;
    for (int j = 0; j + 1 < m; j++)
      left[j + 1] = std::max(left[j], height[hen[i][j]] + 1);
    right[m - 1] = 0;
    for (int j = m; --j;)
      right[j - 1] = std::max(right[j], height[hen[i][j]] + 1);
    for (int j = 0; j < m; j++) {
      min_depth[hen[i][j]] =
          std::max(min_depth[i], depth[i] + std::max(left[j], right[j]));
      dfs1(hen[i][j], i, 1 + std::max({prev_depth, left[j], right[j]}));
      subtrees.push_back({height[hen[i][j]] + 1, enabled_sum[hen[i][j]]});
      if (depth[i] <= max_depth[hen[i][j]]) res++;
      max_depth[i] = std::max(max_depth[i],
                              std::min(max_depth[hen[i][j]],
                                       depth[i] - std::max(left[j], right[j])));
    }
    if (subtrees.size() > 1) {
      std::sort(subtrees.begin(), subtrees.end());
      int upper = subtrees[subtrees.size() - 2].first;
      if (enabled[i])
        res += upper;
      else
        for (auto j : subtrees)
          if (j.second) {
            res += std::max(0, upper - j.first);
            break;
          }
    }
  }
  if (enabled[i]) {
    max_depth[i] = std::max(max_depth[i], depth[i] - height[i]);
    if (!hen[i].size()) res++;
  }
}
int main() {
  int n = ri();
  hen.resize(n);
  for (int i = 1; i < n; i++) {
    int a = ri() - 1;
    int b = ri() - 1;
    hen[a].push_back(b);
    hen[b].push_back(a);
  }
  char s[n + 1];
  scanf("%s", s);
  enabled.resize(n);
  for (int i = 0; i < n; i++) enabled[i] = s[i] == '1';
  all_enabled = std::accumulate(enabled.begin(), enabled.end(), 0);
  height.resize(n);
  depth.resize(n);
  max_depth.resize(n, -1);
  min_depth.resize(n, 1000000000);
  enabled_sum.resize(n);
  dfs0(0, -1);
  dfs1(0, -1, 0);
  printf("%" PRId64 "\n", res);
  return 0;
}
