#include using i64 = long long; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector> adj(n); for (int i = 1; i < n; i++) { int x, y; std::cin >> x >> y; x--, y--; adj[x].push_back(y); adj[y].push_back(x); } std::vector c(n); for (int i = 0; i < n; i++) { std::cin >> c[i]; } int ans = 0; auto dfs = [&](auto self, int x, int p) -> void { for (auto y : adj[x]) { if (y == p) { continue; } self(self, y, x); if (c[y] == 0) { c[y] ^= 1; c[x] ^= 1; ans++; } } }; dfs(dfs, 0, -1); if (c[0] == 0) { ans = -1; } std::cout << ans << "\n"; return 0; }