結果
問題 | No.2236 Lights Out On Simple Graph |
ユーザー |
![]() |
提出日時 | 2023-08-27 00:26:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 688 ms / 4,000 ms |
コード長 | 1,251 bytes |
コンパイル時間 | 1,873 ms |
コンパイル使用メモリ | 208,512 KB |
最終ジャッジ日時 | 2025-02-16 14:55:50 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 57 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll = long long;int main(){ll N, M, m, a, b, vtx, ans=1e9, c=0, mx;cin >> N >> M;m = M/2;vector<pair<ll, ll>> e(M);for (int i=0; i<M; i++){cin >> a >> b; a--; b--;e[i] = {a, b};}for (int i=0; i<N; i++){cin >> a;c |= a*(1LL<<i);}vector<pair<ll, ll>> v;map<ll, ll> mp;mx = 1<<m;for (int i=0; i<mx; i++){vtx = 0;for (int j=0; j<m; j++){if (i & (1<<j)){tie(a, b) = e[j];vtx ^= (1LL<<a); vtx ^= (1LL<<b);}}v.push_back({vtx, __builtin_popcount(i)});}mx = 1<<(M-m);for (int i=0; i<mx; i++){vtx = 0;for (int j=0; j<(M-m); j++){if (i & (1<<j)){tie(a, b) = e[m+j];vtx ^= (1LL<<a); vtx ^= (1LL<<b);}}if (mp.count(vtx)) mp[vtx] = min(mp[vtx], (ll)__builtin_popcount(i));else mp[vtx] = __builtin_popcount(i);}for (auto [vtx, cnt] : v){if (mp.count(vtx ^ c)) ans = min(ans, cnt+mp[vtx ^ c]);}if (ans == 1e9) ans = -1;cout << ans << endl;return 0;}