#include #include #include #include using namespace std; int dfs(const vector> &G, vector &c, int v, int p = -1){ int ans = 0; for(const auto &it: G[v]){ if(it == p) continue; ans += dfs(G, c, it, v); } if(p == -1 && c[v] == 0) return -1; if(c[v] == 0){ c[v] ^= 1; c[p] ^= 1; ans++; } return ans; } int main(){ int n; cin >> n; vector> G(n); for(int i = 0; i < n-1; i++){ int a, b; cin >> a >> b; a--; b--; G[a].emplace_back(b); G[b].emplace_back(a); } vector c(n); for(auto &it: c) cin >> it; cout << dfs(G, c, 0) << endl; return 0; }