#include using namespace std; using ll = long long; int main(){ int N, a, b, ans=0; cin >> N; vector> E(N); vector c(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]; auto dfs=[&](auto self, int from, int p)->int{ int res=0; for (auto to : E[from]){ if (to == p) continue; res += self(self, to, from); } if ((c[from]+res) % 2 == 0){ ans++; return 1; } else return 0; }; a = dfs(dfs, 0, -1); if (a == 1) cout << -1 << endl; else cout << ans << endl; return 0; }