#include <bits/stdc++.h>
using namespace std;
int h[200010], etop, d[200010], lst[200010];
unordered_set<unsigned long long> m;
unsigned long long mi[200010];
char s[200010];
queue<int> q;
vector<int> g[200010];
inline int inn() {
  int x, ch;
  while ((ch = getchar()) < '0' || ch > '9')
    ;
  x = ch ^ '0';
  while ((ch = getchar()) >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ '0');
  return x;
}
int main() {
  int n = inn(), ans = 0;
  mi[0] = 1;
  for (int i = 1; i <= n; i++) mi[i] = mi[i - 1] * 998244353;
  for (int i = 1, u, v; i < n; i++)
    g[u = inn()].push_back(v = inn()), g[v].push_back(u);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] == '1') {
      while (!q.empty()) q.pop();
      memset(d, 0, sizeof(int) * (n + 1));
      q.push(i), d[i] = 1;
      unsigned long long v = 0;
      for (int j = 1, x; !q.empty(); j++) {
        int c = 0;
        while (!q.empty() && d[q.front()] == j)
          v += mi[x = q.front()], q.pop(), lst[++c] = x;
        if (m.count(v)) break;
        m.insert(v), ans++;
        for (int k = 1; k <= c; k++)
          for (int x = lst[k], y, t = 0; t < (int)g[x].size(); t++)
            if (!d[y = g[x][t]]) d[y] = d[x] + 1, q.push(y);
      }
    }
  return !printf("%d\n", ans);
}
