#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> dp;
map<pair<int, int>, bool> ex;
vector<int> edge[200005];
int n;
bool ok[200005];
void dfs(int v, int u) {
  dp[make_pair(u, v)] = 0;
  ex[make_pair(u, v)] = ok[v];
  for (int i = 0; i < edge[v].size(); i++) {
    if (edge[v][i] == u) continue;
    dfs(edge[v][i], v);
    dp[make_pair(u, v)] =
        max(dp[make_pair(u, v)], dp[make_pair(v, edge[v][i])] + 1);
    ex[make_pair(u, v)] |= ex[make_pair(v, edge[v][i])];
  }
}
void dfs2(int v, int u, int mx, bool EX) {
  EX |= ok[v];
  priority_queue<int, vector<int>, greater<int> > S;
  S.push(mx);
  int cnt = 0;
  for (int i = 0; i < edge[v].size(); i++) {
    if (edge[v][i] == u) continue;
    S.push(dp[make_pair(v, edge[v][i])]);
    if (S.size() == 3) S.pop();
    if (ex[make_pair(v, edge[v][i])]) cnt++;
  }
  if (S.size() < 2) return;
  int a = S.top();
  S.pop();
  int b = S.top();
  S.pop();
  for (int i = 0; i < edge[v].size(); i++) {
    if (edge[v][i] == u) continue;
    if (dp[make_pair(v, edge[v][i])] == b)
      dp[make_pair(edge[v][i], v)] = 1 + a;
    else
      dp[make_pair(edge[v][i], v)] = 1 + b;
    if (EX || cnt - ex[make_pair(v, edge[v][i])] >= 1)
      ex[make_pair(edge[v][i], v)] = 1;
    else
      ex[make_pair(edge[v][i], v)] = 0;
    dfs2(edge[v][i], v, dp[make_pair(edge[v][i], v)],
         ex[make_pair(edge[v][i], v)]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  string s;
  cin >> s;
  for (int i = 0; i < n; i++)
    if (s[i] == '1')
      ok[i] = true;
    else
      return 0;
  dfs(0, -1);
  dfs2(0, -1, 0, false);
  long long ret = 0;
  for (int i = 0; i < n; i++) {
    if (!ok[i]) continue;
    priority_queue<int, vector<int>, greater<int> > S;
    for (int j = 0; j < edge[i].size(); j++) {
      S.push(1 + dp[make_pair(i, edge[i][j])]);
      if (S.size() == 3) S.pop();
    }
    ret++;
    if (S.size() == 2) {
      ret += S.top();
    }
  }
  cout << ret + n - 1 << endl;
  return 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < edge[i].size(); j++) {
      int u = i, v = edge[i][j];
      if (u > v) continue;
      bool flag = 0;
      if (dp[make_pair(v, u)] <= dp[make_pair(u, v)]) {
        flag |= ex[make_pair(v, u)];
      }
      if (dp[make_pair(v, u)] >= dp[make_pair(u, v)]) {
        flag |= ex[make_pair(u, v)];
      }
      if (flag) ret++;
    }
  }
  cout << ret << endl;
}
