#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> g[202020];
bool fav[202020];
int far[202020];
int second_farthest[202020];
int closest[202020];
bool in_fav[202020];
int ans = 0;
static const int INF = 0x3f3f3f3f;
void dfs1(int v, int prev) {
  if (fav[v]) in_fav[v] = true;
  for (auto u : g[v])
    if (u != prev) {
      dfs1(u, v);
      in_fav[v] |= in_fav[u];
      far[v] = max(far[v], far[u] + 1);
    }
}
void dfs2(int v, int ma, bool par_fav, int prev) {
  vector<pair<pair<int, int>, bool>> children;
  children.push_back(make_pair(make_pair(0, -1), false));
  for (auto u : g[v]) {
    if (u == prev)
      children.push_back(make_pair(make_pair(ma + 1, u), par_fav));
    else
      children.push_back(make_pair(make_pair(far[u] + 1, u), in_fav[u]));
  }
  vector<pair<int, int>> fav_children;
  for (auto c : children)
    if (c.second)
      fav_children.push_back(make_pair(c.first.first, c.first.second));
  sort(fav_children.begin(), fav_children.end());
  sort(children.begin(), children.end(), greater<pair<pair<int, int>, bool>>());
  if (fav_children.empty())
    closest[v] = INF;
  else
    closest[v] = fav_children[0].first;
  second_farthest[v] = children[1].first.first;
  for (auto u : g[v])
    if (u != prev) {
      int maa = children[u == children[0].first.second ? 1 : 0].first.first;
      bool par_f = fav[v] || par_fav;
      if (!in_fav[u])
        par_f |= !fav_children.empty();
      else
        par_f |= fav_children.size() > 1;
      if (maa < far[u])
        ans += par_f;
      else if (far[u] < maa)
        ans += in_fav[u];
      else
        ans += par_f || in_fav[u];
      dfs2(u, maa, par_f, v);
    }
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) fav[i] = s[i] == '1' ? true : false;
  dfs1(0, -1);
  dfs2(0, 0, fav[0], -1);
  for (int i = 0; i < n; i++) {
    if (fav[i])
      ans += 1 + (second_farthest[i] != -1 ? second_farthest[i] : 0);
    else
      ans += max(0, second_farthest[i] - closest[i] + 1);
  }
  cout << ans << endl;
  return 0;
}
