#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
long long N;
vector<long long> G[222222];
string S;
void dfs(long long v, long long p, long long d, vector<long long> &dist) {
  dist[v] = d;
  for (auto u : G[v]) {
    if (u == p) continue;
    dfs(u, v, d + 1, dist);
  }
}
long long R[222222];
void dfs2(long long v, long long p) {
  R[v] = 0;
  for (auto u : G[v]) {
    if (u == p) continue;
    dfs2(u, v);
    chmax(R[v], R[u] + 1);
  }
}
signed main() {
  cin >> N;
  for (long long i = 0; i < (N - 1); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cin >> S;
  vector<long long> distS(N), distT(N);
  dfs(0, -1, 0, distS);
  long long s = 0;
  for (long long i = 0; i < (N); i++)
    if (distS[i] > distS[s]) s = i;
  dfs(s, -1, 0, distS);
  long long t = 0;
  for (long long i = 0; i < (N); i++)
    if (distS[i] > distS[t]) t = i;
  dfs(t, -1, 0, distT);
  vector<long long> lis;
  for (long long i = 0; i < (N); i++) {
    if (max(distS[i], distT[i]) == (distS[t] + 1) / 2) lis.push_back(i);
  }
  if (lis.size() == 1) {
    dfs2(lis[0], -1);
  } else {
    dfs2(lis[0], lis[1]);
    dfs2(lis[1], lis[0]);
  }
  vector<long long> lim(N);
  for (long long i = 0; i < (N); i++) lim[i] = max(distS[i], distT[i]) - 1;
  for (long long i = 0; i < (N); i++) chmin(lim[i], R[i] + 1);
  long long ans = 0;
  for (long long i = 0; i < (N); i++) ans += lim[i] + 1;
  ans++;
  cout << ans << endl;
  return 0;
}
