結果

問題 No.2286 Join Hands
ユーザー みここみここ
提出日時 2023-02-11 05:04:40
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 1,114 ms
コンパイル使用メモリ 91,416 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 08:23:31
合計ジャッジ時間 3,134 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0