#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> graph[202020];
vector<int> furthest[202020];
int P[202020], Q[202020];
char S[202020];
long long ans;
int predfs(int p, int rt) {
  int ret = 0;
  for (int i = 0; i < graph[p].size(); ++i) {
    if (graph[p][i] == rt) continue;
    furthest[p][i] = predfs(graph[p][i], p) + 1;
    ret = max(ret, furthest[p][i]);
  }
  return ret;
}
void dfs2(int p, int rt, int frr) {
  int best1 = 0, best2 = 0;
  for (int i = 0; i < graph[p].size(); ++i)
    if (graph[p][i] != rt) {
      int f = furthest[p][i];
      if (f > best1) {
        best2 = best1;
        best1 = f;
      } else if (f > best2) {
        best2 = f;
      }
    }
  for (int i = 0; i < graph[p].size(); ++i) {
    if (graph[p][i] == rt) {
      furthest[p][i] = frr;
    } else {
      int nn = furthest[p][i];
      int dd;
      if (nn == best1)
        dd = best2;
      else
        dd = best1;
      dd = max(dd, frr);
      dfs2(graph[p][i], p, dd);
    }
  }
}
void solve(int p, int rt, int rix) {
  if (rt == -1) {
    ans += P[p] + 1;
  } else {
    int ww = furthest[rt][rix];
    ans += ww + 1;
  }
  for (int i = 0; i < graph[p].size(); ++i)
    if (graph[p][i] != rt) {
      solve(graph[p][i], p, i);
    }
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  for (int i = 0; i < N; ++i) furthest[i] = vector<int>(graph[i].size(), -1);
  scanf("%s", S);
  ans = 0;
  predfs(0, -1);
  dfs2(0, -1, 0);
  for (int i = 0; i < N; ++i) {
    P[i] = Q[i] = 0;
    for (int w : furthest[i]) {
      if (w > P[i]) {
        Q[i] = P[i];
        P[i] = w;
      } else if (w > Q[i]) {
        Q[i] = w;
      }
    }
  }
  solve(0, -1, -1);
  printf("%lld\n", ans);
  return 0;
}
