Submission #1128480

#TimeUsernameProblemLanguageResultExecution timeMemory
1128480Alihan_8The Xana coup (BOI21_xanadu)C++20
0 / 100
1096 ms6584 KiB
#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 opt = n + 1; for ( int mask = 0; mask < (1 << n); mask++ ){ vector <int> b = a; for ( int i = 0; i < n; i++ ){ if ( mask >> i & 1 ){ b[i] ^= 1; for ( auto &v: adj[i] ) b[v] ^= 1; } } int mx = 0; for ( auto &v: b ) mx = max(mx, v); if ( mx == 0 ){ int sz = __builtin_popcount(mask); if ( opt != n + 1 ) assert(false); opt = sz; } } if ( opt == n + 1 ) return cout << "impossible\n", 0; cout << opt << '\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...