結果
問題 | No.2236 Lights Out On Simple Graph |
ユーザー |
![]() |
提出日時 | 2023-03-03 21:46:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,238 ms / 4,000 ms |
コード長 | 1,570 bytes |
コンパイル時間 | 2,245 ms |
コンパイル使用メモリ | 203,508 KB |
最終ジャッジ日時 | 2025-02-11 02:14:28 |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 57 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=1000000007,MAX=300005,INF=1<<30; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N,M;cin>>N>>M; vector<pair<int,int>> E(M); for(int i=0;i<M;i++){ int a,b;cin>>a>>b;a--;b--; E[i]=mp(a,b); } ll tar=0; int ans=INF; for(int i=0;i<N;i++){ int c;cin>>c; if(c) tar|=(1LL<<i); } map<ll,int> MA; int K=M/2; for(int bi=0;bi<(1<<K);bi++){ ll now=0; for(int i=0;i<K;i++){ if(bi&(1<<i)){ now^=(1LL<<E[i].fi); now^=(1LL<<E[i].se); } } if(!MA.count(now)) MA[now]=__builtin_popcount(bi); else chmin(MA[now],__builtin_popcount(bi)); } for(int bi=0;bi<(1<<(M-K));bi++){ ll now=tar; for(int i=0;i<M-K;i++){ if(bi&(1<<i)){ now^=(1LL<<E[K+i].fi); now^=(1LL<<E[K+i].se); } } if(MA.count(now)) chmin(ans,MA[now]+__builtin_popcount(bi)); } if(ans==INF) cout<<-1<<endl; else cout<<ans<<endl; }