#include <bits/stdc++.h>
using namespace std;
vector<int> v, emp;
map<vector<int>, int> vis;
int tot, head[1000000], dis[1000000], V[1000000];
char c[1000000];
struct Edge {
  int v, next;
  Edge(int _v = 0, int _n = 0) : v(_v), next(_n) {}
} edge[1000000];
inline void add(int x, int y) {
  edge[++tot] = Edge(y, head[x]);
  head[x] = tot;
}
int main() {
  int n, x, y, la, ans = 0;
  cin >> n;
  for (register int i = 1; i < n; i++)
    scanf("%d%d", &x, &y), add(x, y), add(y, x);
  scanf("%s", c + 1);
  for (register int j = 1; j <= n; j++)
    if (c[j] == '1') {
      queue<int> q;
      q.push(j);
      dis[j] = la = 0;
      v.clear();
      v.swap(emp);
      for (register int i = 1; i <= n; i++) V[i] = 0;
      V[j] = 1;
      while (!q.empty()) {
        int x = q.front();
        q.pop();
        if (dis[x] != la) {
          sort(v.begin(), v.end());
          if (!vis[v]) {
            vis[v] = 1, ans++;
          } else
            break;
          la++;
        }
        v.push_back(x);
        for (register int i = head[x]; i; i = edge[i].next)
          if (!V[edge[i].v])
            dis[edge[i].v] = dis[x] + 1, q.push(edge[i].v), V[edge[i].v] = 1;
      }
      while (!q.empty()) q.pop();
      sort(v.begin(), v.end());
      if (!vis[v]) {
        vis[v] = 1, ans++;
      }
    }
  cout << ans;
  return 0;
}
