#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> G[200005];
vector<pair<long long, long long> > E;
string s;
map<pair<long long, long long>, long long> mp, mp2;
map<pair<long long, long long>, long long> Ginv;
vector<long long> lmin[200005], rmin[200005];
void dfs(int v, int p) {
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (u == p) continue;
    dfs(u, v);
    long long mx = 0, mn = 1000000000;
    for (int j = 0; j < G[u].size(); j++) {
      if (G[u][j] == v) continue;
      mx = max(mx, mp[make_pair(u, G[u][j])]);
      mn = min(mn, mp2[make_pair(u, G[u][j])]);
    }
    mp[make_pair(v, u)] = mx + 1;
    if (s[u] == '1') mn = 0;
    if (s[v] == '1') mn = -1;
    mp2[make_pair(v, u)] = mn + 1;
  }
}
long long lmx[200005], rmx[200005];
long long lmn[200005], rmn[200005];
void dfs2(int v, int p) {
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    lmx[i] = mp[make_pair(v, u)];
    if (i > 0) lmx[i] = max(lmx[i], lmx[i - 1]);
    lmn[i] = mp2[make_pair(v, u)];
    if (i > 0) lmn[i] = min(lmn[i], lmn[i - 1]);
  }
  for (int i = (int)G[v].size() - 1; i >= 0; i--) {
    int u = G[v][i];
    rmx[i] = mp[make_pair(v, u)];
    if (i < (int)G[v].size() - 1) rmx[i] = max(rmx[i], rmx[i + 1]);
    rmn[i] = mp2[make_pair(v, u)];
    if (i < (int)G[v].size() - 1) rmn[i] = min(rmn[i], rmn[i + 1]);
  }
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (u == p) continue;
    long long mx = 0;
    if (i > 0) mx = max(mx, lmx[i - 1]);
    if (i < (int)G[v].size() - 1) mx = max(mx, rmx[i + 1]);
    mp[make_pair(u, v)] = mx + 1;
    long long mn = 1000000000;
    if (i > 0) mn = min(mn, lmn[i - 1]);
    if (i < (int)G[v].size() - 1) mn = min(mn, rmn[i + 1]);
    if (s[v] == '0') mn = 0;
    if (s[u] == '1') mn = -1;
    mp2[make_pair(u, v)] = mn + 1;
  }
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] == p) continue;
    dfs2(G[v][i], v);
  }
}
int main(void) {
  cin >> n;
  long long u, v;
  for (int i = 1; i <= n - 1; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
    E.push_back(make_pair(u, v));
  }
  cin >> s;
  s = "#" + s;
  dfs(1, -1);
  dfs2(1, -1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '1') {
      ans++;
      vector<long long> vec;
      if (G[i].size() <= 1) continue;
      for (int j = 0; j < G[i].size(); j++)
        vec.push_back(mp[make_pair(i, G[i][j])]);
      sort(vec.rbegin(), vec.rend());
      ans += min(vec[0], vec[1]);
    } else {
      vector<long long> vec;
      set<long long> S;
      if (G[i].size() <= 1) continue;
      for (int j = 0; j < G[i].size(); j++) {
        long long dep = mp[make_pair(i, G[i][j])],
                  dep2 = mp2[make_pair(i, G[i][j])];
        if (dep >= dep2) S.insert(dep);
        vec.push_back(dep);
      }
      sort(vec.rbegin(), vec.rend());
      long long mx = vec[0];
      for (auto it = S.begin(); it != S.end(); it++)
        if (*it < mx) ans++;
      if (S.count(mx) && vec[0] == vec[1]) ans++;
    }
  }
  for (int i = 1; i <= n; i++) {
    lmin[i].resize(G[i].size()), rmin[i].resize(G[i].size());
    for (int j = 0; j < G[i].size(); j++) {
      Ginv[make_pair(i, G[i][j])] = j;
      lmin[i][j] = mp2[make_pair(i, G[i][j])];
      if (j > 0) lmin[i][j] = min(lmin[i][j], lmin[i][j - 1]);
      rmin[i][j] = mp2[make_pair(i, G[i][j])];
      if (j < (int)G[i].size() - 1)
        rmin[i][j] = min(rmin[i][j], rmin[i][j + 1]);
    }
  }
  for (int i = 0; i < E.size(); i++) {
    long long u = E[i].first, v = E[i].second;
    long long umx = mp[make_pair(v, u)] - 1, vmx = mp[make_pair(u, v)] - 1;
    long long d = min(umx, vmx);
    long long umx2 = 1000000000, vmx2 = 1000000000;
    if (s[u] == '1') umx2 = 0;
    if (s[v] == '1') vmx2 = 0;
    long long upos = Ginv[make_pair(u, v)], vpos = Ginv[make_pair(v, u)];
    if (upos > 0) umx2 = min(umx2, lmin[u][upos - 1]);
    if (upos < (int)G[u].size() - 1) umx2 = min(umx2, rmin[u][upos + 1]);
    if (vpos > 0) vmx2 = min(vmx2, lmin[v][vpos - 1]);
    if (vpos < (int)G[v].size() - 1) vmx2 = min(vmx2, rmin[v][vpos + 1]);
    if (umx == d && umx >= umx2 || vmx == d && vmx >= vmx2) ans++;
  }
  cout << ans << endl;
  return 0;
}
