結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
22,784 KB
testcase_01 AC 4 ms
15,680 KB
testcase_02 AC 294 ms
93,100 KB
testcase_03 AC 1,386 ms
42,432 KB
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];
int 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]=0;
		}
		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 TM=0;
			for(int u:SCC[i])if(!vis[u])
			{
				++TM;
				while(!vis[u])
				{
					vis[u]=TM;
					u=V[G[u][0]];
				}
				if(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