結果

問題 No.2286 Join Hands
ユーザー shobonvipshobonvip
提出日時 2023-04-28 23:05:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,173 ms / 2,000 ms
コード長 769 bytes
コンパイル時間 4,757 ms
コンパイル使用メモリ 277,880 KB
実行使用メモリ 8,532 KB
最終ジャッジ日時 2024-04-29 00:22:21
合計ジャッジ時間 24,444 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 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 34 ms
5,376 KB
testcase_09 AC 46 ms
5,520 KB
testcase_10 AC 242 ms
6,996 KB
testcase_11 AC 362 ms
7,504 KB
testcase_12 AC 359 ms
7,380 KB
testcase_13 AC 215 ms
6,944 KB
testcase_14 AC 518 ms
7,884 KB
testcase_15 AC 477 ms
7,888 KB
testcase_16 AC 561 ms
8,144 KB
testcase_17 AC 32 ms
5,392 KB
testcase_18 AC 823 ms
8,272 KB
testcase_19 AC 1,127 ms
7,892 KB
testcase_20 AC 1,020 ms
7,884 KB
testcase_21 AC 789 ms
8,148 KB
testcase_22 AC 1,097 ms
7,764 KB
testcase_23 AC 1,173 ms
7,760 KB
testcase_24 AC 887 ms
8,016 KB
testcase_25 AC 1,130 ms
7,760 KB
testcase_26 AC 1,159 ms
7,628 KB
testcase_27 AC 1,159 ms
7,760 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 280 ms
8,400 KB
testcase_48 AC 279 ms
8,524 KB
testcase_49 AC 417 ms
8,400 KB
testcase_50 AC 426 ms
8,528 KB
testcase_51 AC 1,078 ms
7,372 KB
testcase_52 AC 83 ms
6,420 KB
testcase_53 AC 274 ms
8,400 KB
testcase_54 AC 106 ms
6,948 KB
testcase_55 AC 160 ms
7,372 KB
testcase_56 AC 429 ms
8,532 KB
testcase_57 AC 424 ms
8,524 KB
testcase_58 AC 279 ms
8,400 KB
testcase_59 AC 278 ms
8,528 KB
testcase_60 AC 311 ms
8,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef modint998244353 mint;
typedef long long ll;

int main(){
	int n, m; cin >> n >> m;
	mcf_graph<int,int> mcf(4*n + 2);
	for (int i=0; i<n; i++){
		mcf.add_edge(4*n, n+i, 1, 0);
		mcf.add_edge(i, 4*n+1, 1, 0);
		if (i<n-1) mcf.add_edge(n+i, 2*n+i+1, 1, 2);
		if (i>0) mcf.add_edge(n+i, 3*n+i-1, 1, 2);
		mcf.add_edge(2*n+i, i, 1, 0);
		mcf.add_edge(3*n+i, i, 1, 0);
	}
	for (int i=0; i<n-1; i++){
		mcf.add_edge(2*n+i, 2*n+i+1, n, 0);
		mcf.add_edge(3*n+i+1, 3*n+i, n, 0);
	}
	for (int i=0; i<m; i++){
		int u, v; cin >> u >> v;
		u--; v--;
		mcf.add_edge(n+u, v, 1, 0);
		mcf.add_edge(n+v, u, 1, 0);
	}
	auto fl = mcf.flow(4*n, 4*n+1);
	cout << n - fl.second << endl;
}
0