#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long ans = 0;
class Edges {
 public:
  int next, to;
};
Edges edge[maxn * 2];
string w;
int te = 1;
int first[maxn], len1[maxn], len2[maxn], from1[maxn], from2[maxn], f[maxn],
    size[maxn], len3[maxn];
int n, sum = 0;
bool tp[maxn];
void add(int s, int t) {
  ++te;
  edge[te].to = t;
  edge[te].next = first[s];
  first[s] = te;
}
void init(int pos, int fa) {
  size[pos] = tp[pos];
  f[pos] = fa;
  len1[pos] = len2[pos] = 0;
  from1[pos] = from2[pos] = pos;
  for (int e = first[pos]; e; e = edge[e].next) {
    int to = edge[e].to;
    if (to == fa) continue;
    init(to, pos);
    if (from1[pos] == pos || len1[to] + 1 > len1[pos]) {
      len2[pos] = len1[pos];
      from2[pos] = from1[pos];
      len1[pos] = len1[to] + 1;
      from1[pos] = to;
    } else if (from2[pos] == pos || len1[to] + 1 > len2[pos]) {
      len2[pos] = len1[to] + 1;
      from2[pos] = to;
    }
    size[pos] += size[to];
  }
}
void go(int pos, int mlen) {
  len3[pos] = mlen;
  for (int e = first[pos]; e; e = edge[e].next) {
    int to = edge[e].to;
    if (to == f[pos]) continue;
    if (to == from1[pos])
      go(to, max(mlen, len2[pos]) + 1);
    else
      go(to, max(mlen, len1[pos]) + 1);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int s, t;
    cin >> s >> t;
    add(s, t);
    add(t, s);
  }
  cin >> w;
  for (int i = 0; i < n; ++i) tp[i + 1] = w[i] - '0';
  init(1, 0);
  for (int e = first[1]; e; e = edge[e].next) {
    int to = edge[e].to;
    if (from1[1] == to)
      go(to, len2[1] + 1);
    else
      go(to, len1[1] + 1);
  }
  for (int i = 1; i <= n; ++i)
    if (len3[i] > len1[i]) {
      len2[i] = len1[i];
      len1[i] = len3[i];
    } else if (len3[i] > len2[i])
      len2[i] = len3[i];
  for (int i = 1; i <= n; ++i) ans += min(len2[i] + 2, len1[i]);
  cout << ans + 1 << endl;
  return 0;
}
