제출 #1128482

#제출 시각아이디문제언어결과실행 시간메모리
1128482Alihan_8The Xana coup (BOI21_xanadu)C++20
5 / 100
1095 ms6588 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 = min(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...