#include #include using namespace std; int ans = 0; vector c; int dfs(vector> &E, int from, int p){ int cnt=0; for(auto to : E[from]){ if (p == to) continue; cnt += dfs(E, to, from); } if ((cnt + c[from]) % 2 == 0){ ans++; return 1; } else return 0; } int main(){ int N, a, b; cin >> N; vector> E(N); c.resize(N); for (int i=0; i> a >> b; a--; b--; E[a].push_back(b); E[b].push_back(a); } for (int i=0; i> c[i]; if (dfs(E, 0, -1) == 1) cout << -1 << endl; else cout << ans << endl; return 0; }