#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
const int INF = 5e8;
char s[200005];
int tot1;
int n;
vector<int> g[200005];
int size[200005], dist[200005];
int start[200005], fin[200005], cnt;
int msum[200005];
void dfs(int v, int p) {
  size[v] = 1;
  start[v] = cnt;
  msum[cnt + 1] = msum[cnt] + (s[v] == '1' ? 1 : 0);
  ++cnt;
  dist[v] = 0;
  for (auto to : g[v]) {
    if (to == p) continue;
    dfs(to, v);
    size[v] += size[to];
    chmax(dist[v], dist[to] + 1);
  }
  fin[v] = cnt;
}
long long int add = 0;
int subt1(int v) { return msum[fin[v]] - msum[start[v]]; }
int g2[200005];
int ub[200005], lb[200005];
void dfs3(int v, int p, int down) {
  pair<int, int> most, sec;
  most = sec = make_pair(-1, -1);
  most.second = down;
  most.first = p;
  sec.second = 0;
  for (auto to : g[v]) {
    if (to == p) continue;
    int val = dist[to] + 1;
    if (most.second < val) {
      sec = most;
      most = make_pair(to, val);
    } else if (sec.second < val) {
      sec = make_pair(to, val);
    }
  }
  ub[v] = sec.second;
  lb[v] = INF;
  if (s[v] == '1') lb[v] = 0;
  if (most.second > sec.second) {
    g2[v] = most.first;
  }
  if (~p) {
    if (down - 1 < dist[v]) {
      if (tot1 - subt1(v) > 0) ++add;
    } else if (down - 1 > dist[v]) {
      if (subt1(v) > 0) ++add;
    } else {
      ++add;
    }
  }
  for (auto to : g[v]) {
    if (to == p) continue;
    int d;
    if (to == most.first) {
      d = sec.second + 1;
    } else {
      d = most.second + 1;
    }
    dfs3(to, v, d);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  scanf("%s", s);
  for (int i = 0; i < (n); ++i)
    if (s[i] == '1') ++tot1;
  dfs(0, -1);
  memset(g2, -1, sizeof(g2));
  dfs3(0, -1, 0);
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      pq;
  for (int i = 0; i < (n); ++i) {
    pq.push(make_pair(lb[i], i));
  }
  while (!pq.empty()) {
    pair<long long int, long long int> cur = pq.top();
    pq.pop();
    if (~g2[cur.second]) {
      chmin(lb[g2[cur.second]], (int)cur.first + 1);
    }
  }
  long long int res = 0;
  for (int i = 0; i < (n); ++i) res += max(0, ub[i] - lb[i] + 1);
  res += add;
  cout << res << endl;
  return 0;
}
