#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MAX = 2 * 1000 * 100 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;
vector<int> g[MAX];
vector<int> SMIN[MAX];
vector<int> SMAX[MAX];
string s;
int PMIN[MAX];
int PMAX[MAX];
int P[MAX];
int CNT[MAX];
int H[MAX];
void dfs(int v, int p) {
  int ind = -1;
  for (int i = (0); i < ((int)g[v].size()); i++) {
    if (g[v][i] == p) {
      ind = i;
      break;
    }
  }
  if (ind != -1) {
    g[v].erase(g[v].begin() + ind);
  }
  CNT[v] = s[v] == '1';
  for (int i = (0); i < ((int)g[v].size()); i++) {
    int to = g[v][i];
    dfs(to, v);
    H[v] = max(H[v], H[to] + 1);
    CNT[v] += CNT[to];
  }
}
void dfs1(int v) {
  int pmax = -INF;
  int pmin = INF;
  for (int i = (0); i < ((int)g[v].size()); i++) {
    int to = g[v][i];
    PMIN[to] = min(pmin + 1, PMIN[v] + 1);
    if (i + 1 != (int)g[v].size()) PMIN[to] = min(PMIN[to], SMIN[v][i + 1] + 1);
    PMAX[to] = max(pmax + 1, PMAX[v] + 1);
    if (i + 1 != (int)g[v].size()) PMAX[to] = max(PMAX[to], SMAX[v][i + 1] + 1);
    pmax = max(pmax, H[to] + 1);
    pmin = min(pmin, H[to] + 1);
  }
  for (int i = (0); i < ((int)g[v].size()); i++) {
    int to = g[v][i];
    dfs1(to);
  }
}
vector<int> A;
int getMax2(int v) {
  A.clear();
  A.push_back(PMAX[v]);
  for (int i = (0); i < ((int)g[v].size()); i++) {
    int to = g[v][i];
    A.push_back(H[to] + 1);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  if ((int)g[v].size() == 0) {
    if (A[0] > 1) return 1;
    return 0;
  }
  int ans = A[1] + 1;
  while (ans >= A[0]) ans--;
  return ans;
}
int getMin(int v) {
  int ans = INF;
  if (CNT[0] != CNT[v]) {
    ans = min(ans, PMIN[v]);
  }
  for (int i = (0); i < ((int)g[v].size()); i++) {
    int to = g[v][i];
    if (CNT[to] != 0) {
      ans = min(ans, H[to] + 1);
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = (0); i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cin >> s;
  dfs(0, 0);
  for (int v = (0); v < (n); v++) {
    SMIN[v].assign((int)g[v].size(), INF);
    SMAX[v].assign((int)g[v].size(), -INF);
    for (int i = ((int)g[v].size()) - 1; i >= (0); i--) {
      int to = g[v][i];
      if (i + 1 != (int)g[v].size()) SMIN[v][i] = SMIN[v][i + 1];
      SMIN[v][i] = min(SMIN[v][i], H[to] + 1);
      if (i + 1 != (int)g[v].size()) SMAX[v][i] = SMAX[v][i + 1];
      SMAX[v][i] = max(SMAX[v][i], H[to] + 1);
    }
  }
  PMIN[0] = INF;
  PMAX[0] = 0;
  dfs1(0);
  long long ans = 0;
  for (int v = (0); v < ((int)s.size()); v++) {
    if (s[v] == '1') {
      ans += getMax2(v) + 1;
      continue;
    }
    cout << "!!" << getMax2(v) << " " << getMin(v) << endl;
    ans += max(getMax2(v) - getMin(v) + 1, 0);
  }
  cout << ans + 1 << endl;
}
