#include <bits/stdc++.h>
using namespace std;
const int maxn = 200001;
vector<int> e[maxn];
void rm(int x, int p) {
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] == p) {
      swap(e[x][i], e[x].back());
      e[x].pop_back();
    }
  for (int it : e[x]) rm(it, x);
}
int dep[maxn], pass[maxn], cnt[maxn];
bool color[maxn];
int notpass[maxn], pre[maxn];
void dfs(int x) {
  dep[x] = 0;
  pass[x] = 1e9;
  cnt[x] = color[x];
  for (int it : e[x]) {
    dfs(it);
    cnt[x] += cnt[it];
    dep[x] = max(dep[x], dep[it] + 1);
    if (cnt[it]) pass[x] = min(pass[x], dep[it] + 1);
  }
  if (color[x]) pass[x] = min(pass[x], dep[x]);
}
void dfs2(int x) {
  notpass[x] = pre[x] - 1;
  int mx = -1;
  for (int it : e[x]) {
    pre[it] = max(pre[it], mx + 2);
    mx = max(mx, dep[it]);
  }
  mx = -1;
  for (int i = (int)e[x].size() - 1; i >= 0; i--) {
    int it = e[x][i];
    pre[it] = max(pre[it], mx + 2);
    mx = max(mx, dep[it]);
  }
  for (int it : e[x]) {
    pre[it] = max(pre[it], 1 + pre[x]);
    dfs2(it);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1, u, v; i < n; i++) {
    cin >> u >> v;
    e[u].emplace_back(v);
    e[v].emplace_back(u);
  }
  string s;
  cin >> s;
  long long int ans = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == '1') color[i + 1] = true, ans = 1;
  rm(1, 0);
  dfs(1);
  dfs2(1);
  for (int i = 1; i <= n; i++) {
    int low =
        color[i] ? 0 : min(pass[i], (cnt[1] == cnt[i] ? 2000000000 : pre[i]));
    int high = max(dep[i], pre[i]) - 1;
    if (i != 1) high = min(high, dep[i] + 1);
    for (int it : e[i]) high = min(high, pass[it] + 1);
    if (high >= low) ans += high - low + 1;
  }
  cout << ans << endl;
}
