#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
constexpr int inf = 1000000010;
constexpr long long INF = 1000000000000000010;
constexpr long double eps = 1e-12;
constexpr long double pi = 3.141592653589793238;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
vector<vector<int>> graph(200010, vector<int>());
vector<long long> cnt(200010);
void dfs1(int n, int p, int d, vector<int> &dis) {
  dis[n] = d;
  for (int i : graph[n]) {
    if (i == p) continue;
    dfs1(i, n, d + 1, dis);
  }
}
void dfs2(int n, int p) {
  int res = 1;
  for (int i : graph[n]) {
    if (i == p) continue;
    dfs2(i, n);
    chmax(res, cnt[i] + 1);
  }
  cnt[n] = res;
}
vector<long long> ma(200010), val(200010);
void dfs3(int n, int p, vector<int> &d, int rad) {
  ma[n] = rad - d[n] + 1;
  for (int i : graph[n]) {
    if (i == p) continue;
    ma[n] = 0;
  }
  for (int i : graph[n]) {
    if (i == p) continue;
    dfs3(i, n, d, rad);
    chmax(ma[n], ma[i]);
  }
}
void dfs4(int n, int p, string &s) {
  if (s[n] == '1') val[n] = ma[n];
  for (int i : graph[n]) {
    if (i == p) continue;
    dfs4(i, n, s);
    chmax(val[n], val[i]);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vector<int> deg(n);
  for (long long i = 0; i < (n - 1); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(v);
    graph[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  string s;
  cin >> s;
  long long ans = 0;
  vector<int> xd(n), yd(n);
  dfs1(0, -1, 0, xd);
  int ver = -1;
  int tmp = 0;
  for (long long i = 0; i < (n); i++)
    if (chmax(tmp, xd[i])) ver = i;
  dfs1(ver, -1, 0, xd);
  int rver = -1;
  tmp = 0;
  for (long long i = 0; i < (n); i++)
    if (chmax(tmp, xd[i])) rver = i;
  dfs1(rver, -1, 0, yd);
  int diam = xd[rver];
  if (diam & 1) {
    int cen, cen2;
    for (long long i = 0; i < (n); i++) {
      if (xd[i] == diam / 2 && yd[i] == diam / 2 + 1) cen = i;
      if (xd[i] == diam / 2 + 1 && yd[i] == diam / 2) cen2 = i;
    }
    dfs2(cen, cen2);
    dfs2(cen2, cen);
    vector<int> dis(n);
    dfs1(cen, cen2, 0, dis);
    dfs3(cen, cen2, dis, diam / 2);
    dfs4(cen, cen2, s);
    dfs1(cen2, cen, 0, dis);
    dfs3(cen2, cen, dis, diam / 2);
    dfs4(cen2, cen, s);
    for (long long i = 0; i < (n); i++) {
      if (i != cen && i != cen2 && s[i] == '1') ans += cnt[i] + 1;
      if (s[i] == '0' && val[i]) {
        if (i == cen || i == cen2)
          ans += val[i];
        else
          ans += val[i] + 1;
      }
    }
    if (s[cen] == '1') ans += cnt[cen];
    if (s[cen2] == '1') ans += cnt[cen2];
    ans++;
  } else {
    int cen;
    for (long long i = 0; i < (n); i++) {
      if (xd[i] == diam / 2 && yd[i] == diam / 2) cen = i;
    }
    dfs2(cen, -1);
    vector<int> dis(n);
    dfs1(cen, -1, 0, dis);
    dfs3(cen, -1, dis, diam / 2);
    dfs4(cen, -1, s);
    for (long long i = 0; i < (n); i++) {
      if (i == cen) continue;
      if (s[i] == '1')
        ans += cnt[i] + 1;
      else if (val[i])
        ans += val[i] + 1;
    }
    if (s[cen] == '1')
      ans += cnt[cen];
    else
      ans++;
  }
  cout << ans << '\n';
}
