結果

問題 No.2464 To DAG
ユーザー shobonvipshobonvip
提出日時 2023-09-08 23:52:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 364 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 2,593 ms
コンパイル使用メモリ 211,996 KB
実行使用メモリ 51,224 KB
最終ジャッジ日時 2023-09-08 23:52:30
合計ジャッジ時間 19,526 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 364 ms
51,224 KB
testcase_03 AC 351 ms
24,340 KB
testcase_04 AC 326 ms
19,732 KB
testcase_05 AC 309 ms
19,144 KB
testcase_06 AC 302 ms
19,016 KB
testcase_07 AC 227 ms
14,984 KB
testcase_08 AC 276 ms
14,476 KB
testcase_09 AC 244 ms
12,676 KB
testcase_10 AC 252 ms
12,332 KB
testcase_11 AC 168 ms
9,592 KB
testcase_12 AC 128 ms
8,580 KB
testcase_13 AC 165 ms
9,088 KB
testcase_14 AC 219 ms
15,428 KB
testcase_15 AC 283 ms
20,072 KB
testcase_16 AC 145 ms
12,480 KB
testcase_17 AC 19 ms
4,748 KB
testcase_18 AC 78 ms
9,428 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 150 ms
7,752 KB
testcase_23 AC 153 ms
7,952 KB
testcase_24 AC 148 ms
8,252 KB
testcase_25 AC 176 ms
8,132 KB
testcase_26 AC 54 ms
7,188 KB
testcase_27 AC 332 ms
24,584 KB
testcase_28 AC 329 ms
24,464 KB
testcase_29 AC 335 ms
23,300 KB
testcase_30 AC 271 ms
14,836 KB
testcase_31 AC 247 ms
13,264 KB
testcase_32 AC 223 ms
13,372 KB
testcase_33 AC 315 ms
21,176 KB
testcase_34 AC 146 ms
12,568 KB
testcase_35 AC 117 ms
8,296 KB
testcase_36 AC 117 ms
7,832 KB
testcase_37 AC 106 ms
7,468 KB
testcase_38 AC 105 ms
7,396 KB
testcase_39 AC 8 ms
11,168 KB
testcase_40 AC 8 ms
11,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int dfs(int i){
	tansaku[i] = true;
	while(piv[i] < (int)ikeru[i].size()){
		int j = ikeru[i][piv[i]];
		if (tansaku[v[j]]){
			del[j] = true;
			piv[i]++;
			tansaku[i] = false;
			return v[j];
		}
		int g = dfs(v[j]);
		if (g != -1 && g != i){
			del[j] = true;
			piv[i]++;
			tansaku[i] = false;
			return g;
		}else if (g == i){
			del[j] = true;
		}
		piv[i]++;
	}
	tansaku[i] = false;
	return -1;
}

int main(){
	cin >> n >> m;
	ikeru.resize(n);
	piv.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]].push_back(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