#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> e[200000];
int en;
int dist[200000];
int dis[200000];
string s;
int dfs(int v) {
  queue<int> que;
  memset(dist, -1, sizeof(dist));
  que.push(v);
  dist[v] = 0;
  while (!que.empty()) {
    int p = que.front();
    que.pop();
    for (int i = 0; i < e[p].size(); i++) {
      if (dist[e[p][i]] != -1) continue;
      que.push(e[p][i]);
      dist[e[p][i]] = dist[p] + 1;
    }
  }
  int ma = 0;
  for (int i = 0; i < n; i++)
    if (ma < dist[i]) ma = dist[i];
  for (int i = 0; i < n; i++)
    if (dist[i] == ma) en = i;
  memset(dis, -1, sizeof(dis));
  que.push(en);
  dis[en] = 0;
  while (!que.empty()) {
    int p = que.front();
    que.pop();
    for (int i = 0; i < e[p].size(); i++) {
      if (dis[e[p][i]] != -1) continue;
      que.push(e[p][i]);
      dis[e[p][i]] = dis[p] + 1;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  cin >> s;
  dfs(0);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += max(dis[i], dist[i]);
  }
  cout << ans << endl;
}
