結果

問題 No.2464 To DAG
ユーザー kotatsugamekotatsugame
提出日時 2023-09-08 23:41:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 75,948 KB
実行使用メモリ 28,564 KB
最終ジャッジ日時 2023-09-08 23:42:10
合計ジャッジ時間 14,211 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
15,920 KB
testcase_01 AC 5 ms
15,784 KB
testcase_02 AC 233 ms
28,476 KB
testcase_03 AC 223 ms
27,644 KB
testcase_04 AC 172 ms
22,736 KB
testcase_05 AC 172 ms
22,256 KB
testcase_06 AC 155 ms
22,112 KB
testcase_07 AC 116 ms
22,156 KB
testcase_08 AC 137 ms
21,632 KB
testcase_09 AC 154 ms
21,016 KB
testcase_10 AC 122 ms
20,848 KB
testcase_11 AC 86 ms
18,920 KB
testcase_12 AC 70 ms
18,480 KB
testcase_13 AC 90 ms
18,756 KB
testcase_14 AC 119 ms
21,992 KB
testcase_15 AC 169 ms
25,264 KB
testcase_16 AC 89 ms
20,748 KB
testcase_17 AC 16 ms
16,696 KB
testcase_18 AC 52 ms
19,348 KB
testcase_19 AC 5 ms
13,680 KB
testcase_20 AC 5 ms
15,776 KB
testcase_21 AC 5 ms
13,984 KB
testcase_22 AC 71 ms
18,004 KB
testcase_23 AC 71 ms
17,592 KB
testcase_24 AC 71 ms
18,148 KB
testcase_25 AC 71 ms
18,280 KB
testcase_26 AC 34 ms
17,596 KB
testcase_27 AC 228 ms
28,564 KB
testcase_28 AC 203 ms
28,160 KB
testcase_29 AC 196 ms
25,884 KB
testcase_30 AC 142 ms
22,416 KB
testcase_31 AC 128 ms
21,580 KB
testcase_32 AC 125 ms
21,308 KB
testcase_33 AC 192 ms
25,172 KB
testcase_34 AC 80 ms
19,176 KB
testcase_35 AC 62 ms
17,628 KB
testcase_36 AC 62 ms
17,188 KB
testcase_37 AC 53 ms
17,172 KB
testcase_38 AC 51 ms
16,772 KB
testcase_39 AC 7 ms
13,184 KB
testcase_40 AC 8 ms
12,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
using namespace std;
int N,M;
int U[3<<17],V[3<<17];
bool del[3<<17];
vector<int>G[3<<17];
int Gi[3<<17];
bool vis[3<<17];
vector<int>path;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		cin>>U[i]>>V[i];
		U[i]--,V[i]--;
		G[U[i]].push_back(i);
	}
	for(int i=0;i<N;i++)
	{
		path.push_back(i);
		vis[i]=true;
		while(!path.empty())
		{
			int u=path.back();
			if(Gi[u]==G[u].size())
			{
				vis[u]=false;
				path.pop_back();
				continue;
			}
			int ei=G[u][Gi[u]++];
			int v=V[ei];
			path.push_back(v);
			if(!vis[v])
			{
				vis[v]=true;
				continue;
			}
			do{
				path.pop_back();
				int w=path.back();
				vis[w]=false;
				del[G[w][Gi[w]-1]]=true;
			}while(path.back()!=v);
			vis[v]=true;
		}
	}
	vector<pair<int,int> >ans;
	for(int i=0;i<M;i++)if(!del[i])ans.push_back(make_pair(U[i],V[i]));
	cout<<N<<" "<<ans.size()<<"\n";
	for(pair<int,int>e:ans)cout<<e.first+1<<" "<<e.second+1<<"\n";
}
0