#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int n, dep[2][N], maxdep[N];
vector<int> g[N];
void dfs(int c, int fa, int &id, int *dep) {
  dep[c] = fa ? dep[fa] + 1 : 0;
  if (dep[c] > dep[id]) id = c;
  for (auto t : g[c])
    if (t != fa) dfs(t, c, id, dep);
}
int low[N], high[N], dis[N];
long long ans;
void dfs(int c, int fa) {
  dis[c] = 0;
  for (auto t : g[c])
    if (t != fa) {
      dfs(t, c);
      dis[c] = max(dis[c], dis[t] + 1);
    }
  if (s[c] == '1') low[c] = 0;
  if (c == 1)
    ans += max(0, maxdep[c] - low[c] + 1);
  else {
    high[c] = dis[c] + 1;
    if (maxdep[c] == maxdep[fa]) {
      high[c] = dis[c];
      low[fa] = min(low[fa], max(low[c], high[c] + 1));
      ans += max(0, high[c] - low[c] + 1);
    } else {
      low[fa] = min(low[fa], max(low[c] - 1, high[c]));
      ans += max(0, high[c] - low[c] + 1);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < (n); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  scanf("%s", s + 1);
  int u = 0, v = 0, w = 0;
  dfs(1, 0, u, dep[0]);
  dfs(u, 0, v, dep[0]);
  dfs(v, 0, w, dep[1]);
  for (int i = 1; i < (n + 1); ++i) maxdep[i] = max(dep[0][i], dep[1][i]);
  for (int i = 1; i < (n + 1); ++i) low[i] = 1 << 30;
  int rt = min_element(maxdep + 1, maxdep + 1 + n) - maxdep;
  dfs(rt, 0);
  printf("%lld\n", ans);
  return 0;
}
