제출 #986204

#제출 시각아이디문제언어결과실행 시간메모리
986204batsukh2006The Xana coup (BOI21_xanadu)C++17
5 / 100
1049 ms8788 KiB
#include<iostream> #include<stdio.h> #include<math.h> #include<map> #include<string> #include<algorithm> #include<vector> #include<string.h> #include<utility> #include<set> #include<cmath> #include<queue> #include<deque> #include<functional> #include<stack> #include<limits.h> #include<iomanip> #include<unordered_map> #include<numeric> #include<tuple> using namespace std; #define MOD 1000000007 #define int long long #define ff first #define ss second #define endl '\n' void solve(){ int n; cin>>n; vector<int> v[n],c(n); for(int i=1; i<n; i++){ int a,b; cin>>a>>b,a--,b--; v[a].push_back(b); v[b].push_back(a); } int ans=1e9; for(int i=0; i<n; i++) cin>>c[i]; for(int i=0; i<(1<<n); i++){ vector<int> tmp=c; for(int j=0; j<n; j++){ if(i&(1<<j)){ tmp[j]^=1; for(auto node: v[j]){ tmp[node]^=1; } } } int ok=1; for(int j=0; j<n; j++){ if(tmp[j]) ok=0; } int move=__builtin_popcount(i); if(ok) ans=min(ans,move); } if(ans==1e9) cout<<"impossible"; else cout<<ans; } signed main(){ // freopen("248.in", "r", stdin); // freopen("248.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); cout<<endl; } 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...