結果
問題 |
No.2286 Join Hands
|
ユーザー |
|
提出日時 | 2023-02-11 05:04:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 737 bytes |
コンパイル時間 | 859 ms |
コンパイル使用メモリ | 89,128 KB |
最終ジャッジ日時 | 2025-02-10 14:10:06 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 58 |
ソースコード
#include <iostream> #include <atcoder/maxflow> using namespace std; using namespace atcoder; int main() { int n, m; cin >> n >> m; mf_graph<int> g(n * 2 + 2); bool b[200005]{0}; for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--; v--; b[u] = b[v] = true; g.add_edge(u, v + n, 1); g.add_edge(v, u + n, 1); } for(int u = 0; u < n; u++) { g.add_edge(n * 2, u, 1); g.add_edge(u + n, n * 2 + 1, 1); } int ans = g.flow(n * 2, n * 2 + 1) * 2; int c = 0; for(int u = 0; u < n; u++) { c += b[u]; } if(ans == n * 2 - 2 && c == n - 1) { ans -= 2; } cout << ans - n << endl; }