#include <bits/stdc++.h>
using namespace std;
int n, i, x, y, C;
vector<int> list[200011];
char tp[200011];
int down[200011], up[200011], dist[200011], high[200011], low[200011],
    cnt[200011];
vector<pair<int, int> > aux;
long long ans;
void dfs(int node, int root) {
  down[node] = 0;
  for (auto to : list[node]) {
    if (to == root) continue;
    dfs(to, node);
    down[node] = max(down[node], down[to] + 1);
  }
}
void dfs2(int node, int root) {
  aux.clear();
  dist[node] = max(down[node], up[node]);
  for (auto to : list[node]) {
    if (to == root) continue;
    aux.push_back(make_pair(down[to], to));
  }
  if (aux.empty()) return;
  if (aux.size() == 1) {
    up[aux[0].second] = up[node] + 1;
    dfs2(aux[0].second, node);
    return;
  }
  up[aux[0].second] = max(up[node] + 1, aux[1].first + 2);
  for (int i = 1; i < aux.size(); i++)
    up[aux[i].second] = max(up[node] + 1, aux[0].first + 2);
  for (auto e : list[node])
    if (e != root) dfs2(e, node);
}
void solve(int node, int root) {
  down[node] = 0;
  cnt[node] = tp[node] - '0';
  low[node] = 1 << 30;
  if (tp[node] == '1') low[node] = 0;
  for (auto to : list[node]) {
    if (to == root) continue;
    solve(to, node);
    down[node] = max(down[node], down[to] + 1);
    cnt[node] += cnt[to];
    if (cnt[to]) low[node] = min(low[node], down[to] + 1);
  }
  high[node] = min(down[node] + 1, dist[node] - 1);
  if (low[node] <= high[node]) ans += 1LL * (high[node] - low[node] + 1);
}
int main() {
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    list[x].push_back(y);
    list[y].push_back(x);
  }
  scanf("\n%s", tp + 1);
  dfs(1, 0);
  dfs2(1, 0);
  C = min_element(dist + 1, dist + n + 1) - dist;
  solve(C, 0);
  if (cnt[C] == 0) {
    printf("0");
    return 0;
  }
  printf("%lld", ans + 1);
  return 0;
}
