結果

問題 No.2464 To DAG
ユーザー shobonvipshobonvip
提出日時 2023-09-08 23:39:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 900 bytes
コンパイル時間 2,884 ms
コンパイル使用メモリ 215,332 KB
実行使用メモリ 57,008 KB
最終ジャッジ日時 2023-09-08 23:40:14
合計ジャッジ時間 23,103 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 367 ms
57,008 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 221 ms
25,048 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 55 ms
9,716 KB
testcase_27 AC 323 ms
38,636 KB
testcase_28 AC 333 ms
38,216 KB
testcase_29 AC 333 ms
37,688 KB
testcase_30 AC 365 ms
27,528 KB
testcase_31 AC 348 ms
25,556 KB
testcase_32 AC 412 ms
25,032 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 7 ms
17,160 KB
testcase_40 AC 7 ms
17,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

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);
	}
	dfs(0);
	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