結果
問題 |
No.2236 Lights Out On Simple Graph
|
ユーザー |
![]() |
提出日時 | 2023-03-03 21:46:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,612 ms / 4,000 ms |
コード長 | 1,048 bytes |
コンパイル時間 | 4,611 ms |
コンパイル使用メモリ | 260,364 KB |
最終ジャッジ日時 | 2025-02-11 02:16:10 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 57 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint1000000007; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int n,m; void go(vector<pair<int,int>> a,map<long long,int> &mp){ int mm = a.size(); rep(i,1<<mm){ long long B = 0; int s = 0; rep(j,mm){ if((i>>j)&1){ B ^= 1LL<<a[j].first; B ^= 1LL<<a[j].second; s++; } } if(mp.count(B))mp[B] = min(mp[B],s); else mp[B] = s; } } int main(){ cin>>n>>m; vector<pair<int,int>> a,b; rep(i,m){ int x,y; cin>>x>>y; x--,y--; if(a.size()<20){ a.emplace_back(x,y); } else{ b.emplace_back(x,y); } } map<long long,int> mp1,mp2; go(a,mp1); go(b,mp2); long long c = 0; rep(i,n){ int t; cin>>t; if(t)c |= 1LL<<i; } int ans = Inf32; for(auto x:mp1){ if(mp2.count(c^x.first)){ ans = min(ans,x.second + mp2[c^x.first]); } } if(ans==Inf32)ans = -1; cout<<ans<<endl; return 0; }