#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> g[200005];
char s[200005];
int dist[200005], tmp[200005];
void upd(int v, int par, int dd) {
  dist[v] = max(dist[v], dd);
  tmp[v] = dd;
  for (int to : g[v])
    if (to != par) {
      upd(to, v, dd + 1);
    }
}
const int INF = int(1e9);
int h[200005], h2[200005], u[200005];
void dfs1(int v, int par) {
  h[v] = 0;
  h2[v] = -INF;
  for (int to : g[v])
    if (to != par) {
      dfs1(to, v);
      int cur = h[to] + 1;
      if (cur > h[v]) {
        h2[v] = h[v];
        h[v] = cur;
      } else if (cur > h2[v]) {
        h2[v] = cur;
      }
    }
}
void dfs2(int v, int par) {
  u[v] = 0;
  if (par != -1) {
    int cur;
    if (h[par] == h[v] + 1) {
      cur = h2[par] + 1;
    } else {
      cur = h[par] + 1;
    }
    cur = max(cur, u[par] + 1);
    u[v] = cur;
  }
  for (int to : g[v])
    if (to != par) {
      dfs2(to, v);
    }
}
long long ans = 0;
void solve(int v, int par) {
  if (par != -1) {
    int hv = h[v];
    int hpar = u[par];
    if (h[par] == h[v] + 1) {
      hpar = max(hpar, h2[par]);
    } else {
      hpar = max(hpar, h[par]);
    }
    int val1 = max(0, min(dist[v] - hv + 1, dist[par] - hv));
    int val2 = max(0, min(dist[v] - hpar, dist[par] - hpar + 1));
    ans -= val1;
    ans -= val2;
    if (val1 != 0 && val2 != 0) {
      ans += 1;
    }
  }
  for (int to : g[v])
    if (to != par) {
      solve(to, v);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (int)(n - 1); ++i) {
    int from, to;
    scanf("%d%d", &from, &to);
    --from, --to;
    g[from].push_back(to);
    g[to].push_back(from);
  }
  scanf("%s", s);
  for (int i = 0; i < (int)(n); ++i)
    if (s[i] == '0') {
      cout << -1 << endl;
      return 0;
    }
  memset(dist, 0, sizeof dist);
  upd(0, -1, 0);
  int best = 0;
  for (int i = 0; i < (int)(n); ++i)
    if (tmp[i] > tmp[best]) {
      best = i;
    }
  upd(best, -1, 0);
  best = 0;
  for (int i = 0; i < (int)(n); ++i)
    if (tmp[i] > tmp[best]) {
      best = i;
    }
  upd(best, -1, 0);
  for (int i = 0; i < (int)(n); ++i) {
    ans += dist[i] + 1;
  }
  dfs1(0, -1);
  dfs2(0, -1);
  solve(0, -1);
  cout << ans << endl;
  return 0;
}
