#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e10;
template <typename T>
inline void scf(T &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) {
  scf(x);
  return scf(y);
}
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) {
  scf(x);
  scf(y);
  return scf(z);
}
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
  scf(x);
  scf(y);
  scf(z);
  return scf(w);
}
const int N = 2e5 + 100;
int n;
vector<int> g[N];
long long ans;
int dep[N], mx[N];
string s;
void dfs(int u = 1, int par = 0) {
  dep[u] = dep[par] + 1;
  for (auto v : g[u]) {
    if (v != par) {
      dfs(v, u);
      mx[u] = max(mx[u], mx[v]);
    }
  }
  mx[u] = max(mx[u], dep[u]);
  ans += (long long)(max(1, mx[u] - dep[u]) + 1);
  return;
}
int main() {
  scf(n);
  for (int i = 0; i < (n - 1); i++) {
    int u, v;
    scf(u, v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  cin >> s;
  dfs();
  printf("%lld\n", ans);
  return 0;
}
