#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
long long ans = 0;
int n;
vector<int> g[MAXN];
pair<int, int> a[MAXN][2];
string s;
void dfsdown(int v, int f = -1) {
  a[v][0] = pair<int, int>(0, v);
  for (int u : g[v]) {
    if (u == f) continue;
    dfsdown(u, v);
    pair<int, int> t = a[u][0];
    t.second = u;
    t.first++;
    if (t > a[v][0]) {
      a[v][1] = a[v][0];
      a[v][0] = t;
    } else if (t > a[v][1])
      a[v][1] = t;
  }
}
void dfsup(int v, int f = -1) {
  for (int u : g[v]) {
    if (u == f) continue;
    pair<int, int> t;
    if (a[v][0].second == u)
      t = a[v][1];
    else
      t = a[v][0];
    t.first++;
    t.second = v;
    if (t > a[u][0]) {
      a[u][1] = a[u][0];
      a[u][0] = t;
    } else if (t > a[u][1])
      a[u][1] = t;
    dfsup(u, 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);
  }
  cin >> s;
  dfsdown(0, -1);
  dfsup(0, -1);
  for (int i = 0; i < n; ++i) ans += a[i][1].first + 1;
  cout << ans + (n - 1) << endl;
}
