結果
問題 | No.2236 Lights Out On Simple Graph |
ユーザー |
|
提出日時 | 2023-03-03 22:45:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,256 ms / 4,000 ms |
コード長 | 1,658 bytes |
コンパイル時間 | 1,980 ms |
コンパイル使用メモリ | 137,956 KB |
最終ジャッジ日時 | 2025-02-11 03:34:38 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 57 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <functional> #include <cmath> #include <iomanip> #include <stack> #include <queue> #include <numeric> #include <map> #include <unordered_map> #include <set> #include <fstream> #include <chrono> #include <random> #include <bitset> //#include <atcoder/all> #define rep(i,n) for(int i=0;i<(n);i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)(x).size()) #define pb push_back using ll = long long; using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} int main(){ int N,M; cin >> N >> M; vector<pair<int,int>> E(M); rep(i,M){ int a,b; cin >> a >> b; a--; b--; E[i] = {a,b}; } int m1 = M/2; int m2 = M-m1; vector<int> C(N); rep(i,N) cin >> C[i]; ll x = 0; rep(i,N) x += (1LL<<i)*C[i]; map<ll,int> mp1; rep(i,1<<m1){ ll v = 0; rep(j,m1){ if(i&(1<<j)){ v ^= (1LL<<E[j].first) + (1LL<<E[j].second); } } if(mp1.count(v)){ chmin(mp1[v],__builtin_popcount(i)); } else mp1[v] = __builtin_popcount(i); } int ans = 1<<30; rep(i,1<<m2){ ll v = 0; rep(j,m2){ if(i&(1<<j)){ v ^= (1LL<<E[m1+j].first) + (1LL<<E[m1+j].second); } } if(mp1.count(v^x)){ chmin(ans,mp1[v^x]+__builtin_popcount(i)); } } if(ans==1<<30) cout << -1 << endl; else cout << ans << endl; return 0; }