#include using namespace std; using ll = long long; using pll = pair; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1LL << 60; const ll MAX_N = 2e5; vector> T; vector c; vector> dp; void dfs(ll u, ll p){ ll x0=0, x1=0; for(ll v : T[u]){ if(v == p) continue; dfs(v, u); if(dp[v][0]==INF) x1++; if(dp[v][1]==INF) x0++; } if(x0%2==0){ dp[u][c[u]] = 0; dp[u][1-c[u]] = INF; for(ll v : T[u]){ if(v == p) continue; if(dp[v][0]!=INF) dp[u][c[u]] += dp[v][0]+1; else dp[u][c[u]] += dp[v][1]; } }else{ dp[u][c[u]] = INF; dp[u][1-c[u]] = 0; for(ll v : T[u]){ if(v == p) continue; if(dp[v][0]!=INF) dp[u][1-c[u]] += dp[v][0]+1; else dp[u][1-c[u]] += dp[v][1]; } } return; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; T.resize(n); rep(i, n-1){ ll a, b; cin >> a >> b; a--; b--; T[a].pb(b); T[b].pb(a); } c.resize(n); rep(i, n) cin >> c[i]; dp.resize(n, vector(2, 0)); dfs(0, -1); if(dp[0][1]==INF) cout << -1 << endl; else cout << dp[0][1] << endl; }