#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const long long inf = 2e18, mod = 1e9 + 7;
int n, dpD[maxn], dpU[maxn], sum[maxn], psL[maxn], psR[maxn], par[maxn],
    low[maxn], high[maxn];
int arr[maxn], tail;
vector<int> graph[maxn];
char s[maxn];
void dfsD(int u, int prev = -1) {
  sum[u] = (s[u] == '1');
  for (int i : graph[u])
    if (i != prev) {
      dfsD(i, u);
      dpD[u] = max(dpD[u], dpD[i] + 1);
      sum[u] += sum[i];
    }
}
void dfsU(int u, int prev = -1) {
  par[u] = prev;
  if (prev != -1) dpU[u] = max(dpU[u], dpU[prev] + 1);
  for (int i = 0; i < graph[u].size(); i++) {
    int now = graph[u][i];
    if (now != prev)
      psL[i] = psR[i] = dpD[now];
    else
      psL[i] = psR[i] = -mod;
  }
  for (int i = 1; i < graph[u].size(); i++) psL[i] = max(psL[i], psL[i - 1]);
  for (int i = (int)graph[u].size() - 2; i >= 0; i--)
    psR[i] = max(psR[i], psR[i + 1]);
  for (int i = 0; i < graph[u].size(); i++) {
    int now = graph[u][i];
    if (now == prev) continue;
    if (i) dpU[now] = max(dpU[now], psL[i - 1] + 2);
    if (i < graph[u].size() - 1) dpU[now] = max(dpU[now], psR[i + 1] + 2);
  }
  for (int i : graph[u])
    if (i != prev) dfsU(i, u);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    graph[--u].push_back(--v);
    graph[v].push_back(u);
  }
  cin >> s;
  dfsD(0);
  dfsU(0);
  for (int i = 0; i < n; i++) {
    tail = 0;
    arr[tail++] = dpU[i];
    for (int j : graph[i])
      if (j != par[i]) arr[tail++] = dpD[j] + 1;
    sort(arr, arr + tail);
    if (tail == 1)
      high[i] = 1;
    else {
      if (arr[tail - 1] == arr[tail - 2])
        high[i] = arr[tail - 1] - 1;
      else
        high[i] = min(arr[tail - 1] - 1, arr[tail - 2] + 1);
    }
  }
  for (int i = 0; i < n; i++) {
    tail = 0;
    if (par[i] != -1 && sum[0] - sum[i] > 0) arr[tail++] = dpU[i];
    for (int j : graph[i])
      if (j != par[i] && sum[j]) arr[tail++] = dpD[j] + 1;
    if (s[i] == '1')
      low[i] = 0;
    else {
      if (tail == 0)
        low[i] = high[i] + 1;
      else {
        low[i] = *min_element(arr, arr + tail);
      }
    }
  }
  for (int i = 0; i < n; i++) cerr << "HIGH " << i << ':' << high[i] << endl;
  cerr << "______________" << endl;
  for (int i = 0; i < n; i++) cerr << "LOW " << i << ':' << low[i] << endl;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    ans += max(0, high[i] - low[i] + 1);
  }
  cout << ans << endl;
}
