#include <bits/stdc++.h>
using namespace std;
signed main(){
int n; cin >> n;
vector <vector<int>> adj(n);
for ( int i = 1; i < n; i++ ){
int u, v; cin >> u >> v;
--u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector <int> a(n);
for ( auto &u: a ) cin >> u;
int cnt = 0;
for ( int i = 0; i + 1 < n; i++ ){
if ( a[i] != 0 ){
cnt += 1;
a[i] ^= 1, a[i + 1] ^= 1;
if ( i + 2 < n ) a[i + 2] ^= 1;
}
}
if ( a[n - 1] != 0 ) return cout << "impossible\n", 0;
cout << cnt << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |