結果

問題 No.2464 To DAG
ユーザー kotatsugamekotatsugame
提出日時 2023-09-08 22:54:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,252 bytes
コンパイル時間 5,473 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 815,496 KB
最終ジャッジ日時 2023-09-08 22:55:12
合計ジャッジ時間 12,898 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
15,812 KB
testcase_01 AC 5 ms
15,676 KB
testcase_02 AC 324 ms
96,504 KB
testcase_03 AC 1,580 ms
480,264 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
#include<atcoder/scc>
using namespace std;
int N,M;
int U[3<<17],V[3<<17];
bool del[3<<17];
vector<int>G[3<<17];
int ID[3<<17];
int vis[3<<17];
void solve()
{
	atcoder::scc_graph scc(N);
	for(int i=0;i<M;i++)if(!del[i])
	{
		scc.add_edge(U[i],V[i]);
	}
	vector<vector<int> >SCC=scc.scc();
	for(int i=0;i<SCC.size();i++)for(int u:SCC[i])ID[u]=i;
	for(int i=0;i<N;i++)
	{
		G[i].clear();
		vis[i]=0;
	}
	for(int i=0;i<M;i++)if(!del[i]&&ID[U[i]]==ID[V[i]])
	{
		G[U[i]].push_back(i);
	}
	bool ch=false;
	int TM=0;
	for(int i=0;i<N;i++)if(!vis[i])
	{
		++TM;
		int u=i;
		bool ok=true;
		while(vis[u]==0)
		{
			vis[u]=TM;
			if(G[u].empty())
			{
				ok=false;
				break;
			}
			u=V[G[u][0]];
		}
		if(ok&&vis[u]==TM)
		{
			ch=true;
			int w=u;
			do{
				del[G[w][0]]=true;
				w=V[G[w][0]];
			}while(w!=u);
		}
	}
	if(ch)solve();
}
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]--;
	}
	solve();
	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