#include using namespace std; int n; vector> G; vector c; int ans = 0; int dfs(int pos, int pre) { int cnt = 0; for (auto u : G[pos]) { if (u != pre) { cnt += dfs(u, pos); } } if ((cnt + c[pos]) % 2 == 0) { ans++; return 1; } return 0; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; G.resize(n); c.resize(n); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); G[b].push_back(a); } for (int i = 0; i < n; i++) { cin >> c[i]; } cout << (dfs(0, -1) == 0 ? ans : -1) << endl; }