結果

問題 No.2464 To DAG
ユーザー shobonvipshobonvip
提出日時 2023-09-08 23:50:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 455 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 2,618 ms
コンパイル使用メモリ 216,600 KB
実行使用メモリ 57,004 KB
最終ジャッジ日時 2023-09-08 23:50:35
合計ジャッジ時間 22,178 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 417 ms
57,004 KB
testcase_03 AC 404 ms
37,028 KB
testcase_04 AC 403 ms
33,880 KB
testcase_05 AC 433 ms
33,712 KB
testcase_06 AC 455 ms
33,532 KB
testcase_07 AC 292 ms
22,300 KB
testcase_08 AC 347 ms
24,088 KB
testcase_09 AC 317 ms
22,552 KB
testcase_10 AC 365 ms
21,904 KB
testcase_11 AC 214 ms
16,716 KB
testcase_12 AC 163 ms
14,076 KB
testcase_13 AC 235 ms
17,012 KB
testcase_14 AC 238 ms
23,032 KB
testcase_15 AC 336 ms
27,836 KB
testcase_16 AC 153 ms
16,844 KB
testcase_17 AC 19 ms
5,416 KB
testcase_18 AC 83 ms
11,196 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 300 ms
19,928 KB
testcase_23 AC 320 ms
19,856 KB
testcase_24 AC 292 ms
19,884 KB
testcase_25 AC 305 ms
19,972 KB
testcase_26 AC 61 ms
9,156 KB
testcase_27 AC 414 ms
36,744 KB
testcase_28 AC 409 ms
33,452 KB
testcase_29 AC 412 ms
33,504 KB
testcase_30 AC 390 ms
25,532 KB
testcase_31 AC 363 ms
20,972 KB
testcase_32 AC 367 ms
20,408 KB
testcase_33 AC 355 ms
29,560 KB
testcase_34 AC 189 ms
16,608 KB
testcase_35 AC 238 ms
20,116 KB
testcase_36 AC 259 ms
19,840 KB
testcase_37 AC 212 ms
19,840 KB
testcase_38 AC 218 ms
19,816 KB
testcase_39 AC 9 ms
17,096 KB
testcase_40 AC 9 ms
17,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int n, m;
vector<set<int>> ikeru;
vector<bool> del;
vector<bool> tansaku;
int u[350000], v[350000];

int dfs(int i){
	tansaku[i] = true;
	while(!ikeru[i].empty()){
		auto jf = ikeru[i].begin();
		int j = *jf;
		if (tansaku[v[j]]){
			del[j] = true;
			ikeru[i].erase(jf);
			tansaku[i] = false;
			return v[j];
		}
		int g = dfs(v[j]);
		if (g != -1 && g != i){
			del[j] = true;
			ikeru[i].erase(jf);
			tansaku[i] = false;
			return g;
		}else if (g == i){
			del[j] = true;
		}
		ikeru[i].erase(jf);
	}
	tansaku[i] = false;
	return -1;
}

int main(){
	cin >> n >> m;
	ikeru.resize(n);
	del.resize(m);
	tansaku.resize(n);
	for (int i=0; i<m; i++){
		cin >> u[i] >> v[i];
		u[i]--;
		v[i]--;
		ikeru[u[i]].insert(i);
	}
	for (int i=0; i<n; i++){
		dfs(i);
	}
	vector<pair<int,int>> ans;
	for (int i=0; i<m; i++){
		if (!del[i]){
			ans.push_back(pair(u[i]+1, v[i]+1));
		}
	}
	cout << n << ' ' << (int)ans.size() << '\n';
	for (int i=0; i<(int)ans.size(); i++){
		cout << ans[i].first << ' ' << ans[i].second << '\n';
	}
}
0