Submission #574145

#TimeUsernameProblemLanguageResultExecution timeMemory
574145talant117408The Xana coup (BOI21_xanadu)C++17
5 / 100
1084 ms7888 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define pb push_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define sz(v) int((v).size()) #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl '\n' int mod = 1e9+7; ll modulo(ll a) { return ((a % mod) + mod) % mod; } ll add(ll a, ll b) { return modulo(a + b); } ll mult(ll a, ll b) { return modulo(a * b); } ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b&1) { res = mult(res, a); } a = mult(a, a); b >>= 1; } return res; } const int N = 1e5+7; vector <int> graph[N]; int color[N]; void check(int n) { int mn = 2e9; for (int mask = 0; mask < (1 << n); mask++) { vector <int> c(n); for (int i = 0; i < n; i++) c[i] = color[i]; for (int i = 0; i < n; i++) { if (mask & (1 << i)) { c[i] ^= 1; for (auto to : graph[i]) { c[to] ^= 1; } } } int flag = 0; for (int i = 0; i < n; i++) flag |= c[i]; if (!flag) { mn = min(mn, __builtin_popcount(mask)); } } if (mn < 2e9) { cout << mn << endl; exit(0); } } void solve() { int n; cin >> n; for (int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; a--; b--; graph[a].pb(b); graph[b].pb(a); } for (int i = 0; i < n; i++) { cin >> color[i]; } check(n); cout << "impossible" << endl; } int main() { do_not_disturb int t = 1; //~ cin >> t; while (t--) { solve(); } return 0; }
#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...