Submission #399098

#TimeUsernameProblemLanguageResultExecution timeMemory
399098Jarif_RahmanThe Xana coup (BOI21_xanadu)C++17
0 / 100
1088 ms14524 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll inf = 1e9; int n; ll ans = inf; vector<int> ss; vector<vector<int>> v; vector<int> state; void bruteforce(int k){ if(k == n){ auto new_state = state; for(int x: ss){ new_state[x] = !new_state[x]; for(int y: v[x]) new_state[y] = !new_state[y]; if(all_of(new_state.begin(), new_state.end(), [&](int z){return z==0;})) ans = min(ans, (ll)ss.size()); } return; } ss.pb(k); bruteforce(k+1); ss.pop_back(); bruteforce(k+1); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; v.resize(n); state.resize(n); for(int i = 0; i < n-1; i++){ int a, b; cin >> a >> b; a--, b--; v[a].pb(b); v[b].pb(a); } for(int &x: state) cin >> x; bruteforce(0); if(ans >= inf) cout << "impossible\n"; cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...