結果
問題 |
No.2236 Lights Out On Simple Graph
|
ユーザー |
|
提出日時 | 2023-03-24 13:24:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,789 bytes |
コンパイル時間 | 1,670 ms |
コンパイル使用メモリ | 178,896 KB |
実行使用メモリ | 52,608 KB |
最終ジャッジ日時 | 2024-09-18 16:20:45 |
合計ジャッジ時間 | 23,833 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 WA * 18 |
ソースコード
// Problem: No.2236 Lights Out On Simple GraphNo.2236 熄灯简图 // Contest: yukicoder // URL: https://yukicoder.me/problems/no/2236 // Memory Limit: 512 MB // Time Limit: 4000 ms #include <bits/stdc++.h> #define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define dbg(x) cout << #x << " = " << (x) << "\n"; #define popcount(x) __builtin_popcountll((x)) #define all(v) (v).begin(), (v).end() #define pb emplace_back #define x first #define y second using namespace std; typedef long long ll; typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int n, m; int st; void solve() { cin >> n >> m; vector<pll> edges(m); for (auto &e : edges) { cin >> e.x >> e.y; e.x--, e.y--; } for (int i = 0; i < n; i++) { int x; cin >> x; st |= x << i; } int nn = m / 2; map<int, int> vis; for (int j = 0; j < (1 << nn); j++) { int state = 0; for (int k = 0; k < nn; k++) { if (j & (1 << k)) { int x = edges[k].x, y = edges[k].y; state ^= (1 << x); state ^= (1 << y); } } if (vis.count(state)) vis[state] = min(vis[state], popcount(j)); else vis[state] = popcount(j); } int rest = m - nn; int ans = -1; for (int j = 0; j < (1 << rest); j++) { int state = 0; for (int k = 0; k < rest; k++) { if (j & (1 << k)) { int x = edges[nn + k].x, y = edges[nn + k].y; state ^= (1 << x); state ^= (1 << y); } } if (vis.count(state ^ st)) { if (ans == -1) ans = vis[state ^ st] + popcount(j); else ans = min(vis[state ^ st] + popcount(j), ans); } } cout << ans << "\n"; } int main() { fastio; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }