#include <bits/stdc++.h>
using namespace std;
int n, pow2[1005][2];
char s[1005];
vector<int> dep[1005];
struct node {
  int v;
  node *nxt;
} edge[1005 * 2], *head[1005], *ncnt;
set<pair<int, int> > vis;
void addedge(int u, int v) {
  ncnt++;
  ncnt->v = v, ncnt->nxt = head[u];
  head[u] = ncnt;
}
void dfs(int u, int fa, int d) {
  dep[d].push_back(u);
  for (node *p = head[u]; p; p = p->nxt) {
    int v = p->v;
    if (v == fa) continue;
    dfs(v, u, d + 1);
  }
}
int main() {
  scanf("%d", &n);
  pow2[0][0] = pow2[0][1] = 1;
  for (int i = 1; i <= n; i++) {
    pow2[i][0] = pow2[i - 1][0] * 2 % 1000000007;
    pow2[i][1] = pow2[i - 1][1] * 2 % 998244353;
  }
  ncnt = &edge[0];
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
  }
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] == '1') {
      memset(dep, 0, sizeof(dep));
      dfs(i, 0, 0);
      int x1 = 0, x2 = 0;
      for (int i = 0; dep[i].size(); i++) {
        for (int j = 0, siz = dep[i].size(); j < siz; j++) {
          int x = dep[i][j];
          x1 = (x1 + pow2[x][0]) % 1000000007,
          x2 = (x2 + pow2[x][1]) % 998244353;
        }
        if (vis.find(pair<int, int>(x1, x2)) == vis.end())
          vis.insert(pair<int, int>(x1, x2));
      }
    }
  printf("%d\n", vis.size());
}
