#include <bits/stdc++.h>
using namespace std;
int N;
string S;
vector<int> E[202020];
vector<pair<int, int>> V[202020];
vector<pair<int, int>> L[202020], R[202020];
int A[202020], B[202020];
signed long long ret = 0;
map<int, pair<int, int>> memo[202020];
pair<int, int> dfs(int cur, int pre) {
  V[cur].resize(E[cur].size());
  int D = 0, is = S[cur], i;
  for (i = 0; i < (E[cur].size()); i++) {
    int r = E[cur][i];
    if (r != pre) {
      V[cur][i] = dfs(r, cur);
      V[cur][i].first++;
      D = max(D, V[cur][i].first);
      is |= V[cur][i].second;
    }
  }
  return memo[cur][pre] = make_pair(D, is);
}
void dfs2(int cur, int pre, pair<int, int> par) {
  par.first++;
  int i;
  for (i = 0; i < (E[cur].size()); i++) {
    int r = E[cur][i];
    if (r == pre) V[cur][i] = par;
  }
  L[cur].resize(E[cur].size());
  R[cur].resize(E[cur].size());
  for (i = 1; i < L[cur].size(); i++) {
    L[cur][i].first = max(L[cur][i - 1].first, V[cur][i - 1].first);
    L[cur][i].second = L[cur][i - 1].second | V[cur][i - 1].second;
  }
  for (i = R[cur].size() - 2; i >= 0; i--) {
    R[cur][i].first = max(R[cur][i + 1].first, V[cur][i + 1].first);
    R[cur][i].second = R[cur][i + 1].second | V[cur][i + 1].second;
  }
  for (i = 0; i < (E[cur].size()); i++) {
    int r = E[cur][i];
    if (r != pre) {
      pair<int, int> p = {max(L[cur][i].first, R[cur][i].first),
                          L[cur][i].second | R[cur][i].second};
      memo[cur][r] = p;
      dfs2(r, cur, p);
    }
  }
}
void centerv(int a) {
  vector<pair<int, int>> C = V[a];
  C.push_back({0, S[a]});
  C.push_back({0, S[a]});
  sort((C.begin()), (C.end()));
  reverse((C.begin()), (C.end()));
  int Rmax = C[1].first;
  int Rmin = 201010;
  for (auto& v : C)
    if (v.second) Rmin = min(Rmin, v.first);
  if (Rmin <= Rmax) {
    ret += Rmax - Rmin + 1;
  }
}
void centere(int a, int b) {
  pair<int, int> p[2] = {memo[a][b], memo[b][a]};
  if (p[0].first < p[1].first) {
    ret += p[0].second;
  } else if (p[0].first > p[1].first) {
    ret += p[1].second;
  } else {
    ret++;
  }
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (i = 0; i < (N - 1); i++) {
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;
    E[A[i]].push_back(B[i]);
    E[B[i]].push_back(A[i]);
  }
  cin >> S;
  for (auto& c : S) c -= '0';
  auto p = dfs(0, -1);
  dfs2(0, -1, {0, 0});
  for (i = 0; i < (N); i++) centerv(i);
  for (i = 0; i < (N - 1); i++) centere(A[i], B[i]);
  cout << ret << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
