結果

問題 No.2464 To DAG
ユーザー 👑 kmjpkmjp
提出日時 2023-09-08 22:52:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 657 ms / 2,000 ms
コード長 1,514 bytes
コンパイル時間 2,374 ms
コンパイル使用メモリ 212,344 KB
実行使用メモリ 34,824 KB
最終ジャッジ日時 2023-09-08 22:52:32
合計ジャッジ時間 24,495 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,420 KB
testcase_01 AC 6 ms
10,464 KB
testcase_02 AC 580 ms
34,824 KB
testcase_03 AC 629 ms
20,408 KB
testcase_04 AC 535 ms
15,980 KB
testcase_05 AC 477 ms
15,704 KB
testcase_06 AC 463 ms
15,420 KB
testcase_07 AC 425 ms
15,908 KB
testcase_08 AC 466 ms
15,776 KB
testcase_09 AC 411 ms
15,320 KB
testcase_10 AC 393 ms
15,244 KB
testcase_11 AC 283 ms
13,468 KB
testcase_12 AC 223 ms
12,896 KB
testcase_13 AC 255 ms
13,328 KB
testcase_14 AC 406 ms
15,684 KB
testcase_15 AC 459 ms
18,840 KB
testcase_16 AC 258 ms
14,748 KB
testcase_17 AC 46 ms
11,220 KB
testcase_18 AC 177 ms
13,632 KB
testcase_19 AC 5 ms
10,344 KB
testcase_20 AC 6 ms
10,472 KB
testcase_21 AC 5 ms
10,468 KB
testcase_22 AC 153 ms
12,452 KB
testcase_23 AC 158 ms
12,260 KB
testcase_24 AC 150 ms
12,756 KB
testcase_25 AC 149 ms
12,936 KB
testcase_26 AC 117 ms
12,068 KB
testcase_27 AC 657 ms
21,540 KB
testcase_28 AC 633 ms
22,416 KB
testcase_29 AC 623 ms
20,464 KB
testcase_30 AC 540 ms
18,644 KB
testcase_31 AC 536 ms
17,976 KB
testcase_32 AC 515 ms
17,868 KB
testcase_33 AC 419 ms
19,524 KB
testcase_34 AC 209 ms
14,912 KB
testcase_35 AC 166 ms
12,836 KB
testcase_36 AC 162 ms
12,348 KB
testcase_37 AC 81 ms
12,060 KB
testcase_38 AC 82 ms
12,260 KB
testcase_39 AC 23 ms
10,432 KB
testcase_40 AC 23 ms
10,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
vector<int> E[303030];
vector<pair<int,int>> R;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
	}
	
	
	FOR(i,N) {
		vector<int> V;
		set<int> S;
		V.push_back(i);
		S.insert(i);
		while(V.size()) {
			while(E[V.back()].size()) {
				x=E[V.back()].back();
				E[V.back()].pop_back();
				if(S.count(x)) {
					while(V.back()!=x) {
						S.erase(V.back());
						V.pop_back();
					}
					continue;
				}
				S.insert(x);
				V.push_back(x);
			}
			if(V.size()>=2) {
				S.erase(V.back());
				R.push_back({V[V.size()-2]+1,V[V.size()-1]+1});
			}
			V.pop_back();
		}
	}
	cout<<N<<" "<<R.size()<<endl;
	FORR2(a,b,R) cout<<a<<" "<<b<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0