제출 #783600

#제출 시각아이디문제언어결과실행 시간메모리
783600christinelynnThe Xana coup (BOI21_xanadu)C++17
5 / 100
1081 ms7272 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int MAX=1e9; int n; vector<vector<int>> adj; bool can(vector<int> c, int mask) { int i=0; while(mask) { if(mask&1) { c[i]^=1; for(int p : adj[i]) c[p]^=1; } mask>>=1; i++; } int sum=0; for(int p : c) sum+=p; return sum==0; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; adj.resize(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); } int ans=MAX; vector<int> c(n); for(int &p : c) cin >> p; for(int i=0; i<(1 << n); i++) if(can(c, i)) ans=min(ans, (int)__builtin_popcount(i)); if(ans>=MAX) cout << "impossible\n"; else cout << ans << '\n'; 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...