結果

問題 No.2464 To DAG
ユーザー kotatsugamekotatsugame
提出日時 2023-09-08 22:28:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,182 bytes
コンパイル時間 1,814 ms
コンパイル使用メモリ 76,484 KB
実行使用メモリ 37,592 KB
最終ジャッジ日時 2023-09-08 22:28:54
合計ジャッジ時間 18,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
18,228 KB
testcase_01 WA -
testcase_02 AC 243 ms
32,528 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 231 ms
31,128 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 6 ms
13,984 KB
testcase_20 AC 6 ms
18,108 KB
testcase_21 AC 5 ms
14,076 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 50 ms
23,132 KB
testcase_27 AC 367 ms
37,392 KB
testcase_28 AC 366 ms
37,592 KB
testcase_29 AC 375 ms
37,584 KB
testcase_30 AC 277 ms
30,624 KB
testcase_31 AC 203 ms
30,044 KB
testcase_32 AC 180 ms
30,016 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 7 ms
14,112 KB
testcase_40 AC 8 ms
18,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
using namespace std;
int N,M;
int U[6<<17],V[6<<17];
int deg[3<<17];
bool del[6<<17];
vector<int>G[3<<17];
int Gi[3<<17];
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]--;
		deg[U[i]]++;
		deg[V[i]]--;
		G[U[i]].push_back(i);
	}
	vector<int>from,to;
	for(int i=0;i<N;i++)
	{
		if(deg[i]>=0)
		{
			for(int j=0;j<deg[i];j++)to.push_back(i);
		}
		else
		{
			for(int j=0;j<-deg[i];j++)from.push_back(i);
		}
	}
	assert(to.size()==from.size());
	for(int i=0;i<to.size();i++)
	{
		int sz=M+i;
		U[sz]=from[i];
		V[sz]=to[i];
		G[from[i]].push_back(sz);
	}
	vector<int>Es;
	for(int i=0;i<N;i++)while(Gi[i]<G[i].size())
	{
		int u=i;
		bool D=true;
		Es.clear();
		do{
			assert(Gi[u]<G[u].size());
			int ei=G[u][Gi[u]++];
			Es.push_back(ei);
			if(ei>=M)D=false;
			u=V[ei];
		}while(u!=i);
		if(D)for(int ei:Es)del[ei]=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