結果

問題 No.2464 To DAG
ユーザー kotatsugamekotatsugame
提出日時 2023-09-08 22:59:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,234 bytes
コンパイル時間 1,112 ms
コンパイル使用メモリ 87,748 KB
実行使用メモリ 91,968 KB
最終ジャッジ日時 2023-09-08 22:59:50
合計ジャッジ時間 9,203 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
20,216 KB
testcase_01 AC 5 ms
15,696 KB
testcase_02 AC 352 ms
91,968 KB
testcase_03 TLE -
testcase_04 TLE -
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];
bool vis[3<<17];
void solve()
{
	bool ch=false;
	{
		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]=false;
		}
		for(int i=0;i<M;i++)if(!del[i]&&ID[U[i]]==ID[V[i]])
		{
			G[U[i]].push_back(i);
		}
		for(int i=0;i<SCC.size();i++)if(SCC[i].size()>=2)
		{
			int u=SCC[i][0];
			while(!vis[u])
			{
				vis[u]=true;
				assert(!G[u].empty());
				u=V[G[u][0]];
			}
			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