結果

問題 No.2286 Join Hands
ユーザー t98slidert98slider
提出日時 2023-04-28 23:16:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,081 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 4,328 ms
コンパイル使用メモリ 245,172 KB
実行使用メモリ 8,552 KB
最終ジャッジ日時 2024-04-29 00:29:52
合計ジャッジ時間 24,206 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 29 ms
5,376 KB
testcase_09 AC 40 ms
5,420 KB
testcase_10 AC 225 ms
6,948 KB
testcase_11 AC 358 ms
7,524 KB
testcase_12 AC 357 ms
7,272 KB
testcase_13 AC 201 ms
6,628 KB
testcase_14 AC 528 ms
7,912 KB
testcase_15 AC 476 ms
7,656 KB
testcase_16 AC 550 ms
8,044 KB
testcase_17 AC 26 ms
5,376 KB
testcase_18 AC 824 ms
8,168 KB
testcase_19 AC 1,053 ms
7,780 KB
testcase_20 AC 982 ms
7,912 KB
testcase_21 AC 807 ms
8,292 KB
testcase_22 AC 1,039 ms
7,788 KB
testcase_23 AC 1,067 ms
7,608 KB
testcase_24 AC 864 ms
8,040 KB
testcase_25 AC 1,059 ms
7,656 KB
testcase_26 AC 1,081 ms
7,532 KB
testcase_27 AC 1,076 ms
7,780 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 243 ms
8,296 KB
testcase_48 AC 243 ms
8,424 KB
testcase_49 AC 376 ms
8,552 KB
testcase_50 AC 380 ms
8,420 KB
testcase_51 AC 1,056 ms
7,268 KB
testcase_52 AC 276 ms
6,440 KB
testcase_53 AC 240 ms
8,296 KB
testcase_54 AC 94 ms
6,764 KB
testcase_55 AC 140 ms
7,272 KB
testcase_56 AC 381 ms
8,552 KB
testcase_57 AC 376 ms
8,300 KB
testcase_58 AC 243 ms
8,420 KB
testcase_59 AC 243 ms
8,552 KB
testcase_60 AC 1,060 ms
8,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, u, v;
    cin >> n >> m;
    atcoder::mcf_graph<int, int> g(4 * n + 2);
    int s = 4 * n, t = s + 1;
    for(int i = 0; i < m; i++){
        cin >> u >> v;
        u--, v--;
        g.add_edge(v, u + 3 * n, 2, 0);
        g.add_edge(u, v + 3 * n, 2, 0);
    }
    for(int i = 0; i < n; i++){
        g.add_edge(s, i, 2, 0);

        g.add_edge(i + n, i + 3 * n, 2, 0);
        g.add_edge(i + 2 * n, i + 3 * n, 2, 0);

        g.add_edge(i + 3 * n, t, 2, 0);

        if(i >= 1){
            g.add_edge(i + n, i + n - 1, 1 << 30, 0);
            g.add_edge(i, i + n - 1, 2, 1);
        }

        if(i + 1 < n){
            g.add_edge(i + 2 * n, i + 2 * n + 1, 1 << 30, 0);
            g.add_edge(i, i + 2 * n + 1, 2, 1);
        }
    }
    auto p = g.flow(s, t);
    cout << n - p.second << '\n';
}
0