結果
問題 | No.2236 Lights Out On Simple Graph |
ユーザー |
![]() |
提出日時 | 2023-03-09 20:24:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,178 bytes |
コンパイル時間 | 4,264 ms |
コンパイル使用メモリ | 267,528 KB |
最終ジャッジ日時 | 2025-02-11 07:14:05 |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 47 WA * 10 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;using ll = long long;using mint = modint998244353;#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define repf(i, n, flag) for (int i = 0; i < (int)(n) && flag; i++)#define all(v) v.begin(), v.end()const int INF = 1e9;int main() {int n, m;cin >> n >> m;vector dp(n, vector<int>(n, INF));rep(i, m) {int a, b;cin >> a >> b;a--; b--;dp[a][b] = dp[b][a] = 1;}int cnt = 0;vector<int> c(n);rep(i, n) {cin >> c[i];if(c[i] == 1) cnt++;}rep(k, n) rep(i, n) rep(j, n) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);mcf_graph<int, int> g(2*n+2);int s = 2*n, t = s + 1;rep(i, n) g.add_edge(s, i, 1, 0);rep(i, n) g.add_edge(n+i, t, 1, 0);rep(i, n) rep(j, n) {if(i == j) continue;if(c[i] == 0) continue;if(c[j] == 0) continue;if(dp[i][j] >= INF) continue;g.add_edge(i, n+j, 1, dp[i][j]);}auto res = g.flow(s, t);if(res.first < cnt) cout << -1 << endl;else cout << res.second / 2 << endl;}