#include <bits/stdc++.h>
using namespace std;
const int MX = 1 << 18;
const int MM = 1000000007;
int N;
char D[MX];
vector<int> T[MX];
int lev[MX], vst[MX], d1[MX], d2[MX];
int cnt[MX];
void bfs(int x, int d[MX]) {
  queue<int> Q;
  for (int i = 0; i < MX; i++) d[i] = 0;
  Q.push(x);
  d[x] = 1;
  while (Q.size()) {
    int p = Q.front();
    Q.pop();
    for (int c : T[p]) {
      if (d[c]) continue;
      d[c] = d[p] + 1;
      Q.push(c);
    }
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 2; i <= N; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    T[a].push_back(b);
    T[b].push_back(a);
  }
  scanf("%s", D + 1);
  for (int i = 1; i <= N; i++)
    if (D[i] != '1') return !printf("-1\n");
  bfs(1, d1);
  int c = 1, d = 1;
  for (int i = 2; i <= N; i++)
    if (d1[c] < d1[i]) c = i;
  bfs(c, d1);
  for (int i = 2; i <= N; i++)
    if (d1[d] < d1[i]) d = i;
  bfs(d, d2);
  for (int i = 1; i <= N; i++) cnt[i] = T[i].size();
  queue<int> Q;
  for (int i = 1; i <= N; i++) {
    vst[i] = 0;
    if (T[i].size() == 1) Q.push(i), vst[i] = 1;
  }
  while (Q.size()) {
    int p = Q.front();
    Q.pop();
    for (int c : T[p]) {
      if (vst[c]) continue;
      lev[c] = max(lev[c], lev[p] + 1);
      if (--cnt[c] == 1) Q.push(c), vst[c] = 1;
    }
  }
  long long ans = 1;
  for (int i = 1; i <= N; i++) ans += min(max(d2[i], d1[i]) - 1, lev[i] + 2);
  printf("%lld\n", ans);
}
