179752025-09-24 18:10:50algoproTestnevelés óracpp17Wrong answer 7/50215ms64000 KiB
// UUID: b4f93e61-43eb-4ed3-991e-ef3736c2a8f7
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> graph;
vector<bool> been;
vector<int> solution;

void dfs(int node){
	for(int next:graph[node]){
		if(!been[next]) dfs(next);
	}
	solution.push_back(node);
	been[node]=true;
return;
}


int main() {
	int N,K;
	cin >> N >> K;
	graph.resize(N+1);

	for(int i=0; i<K; i++){
		int a,b;
		cin >> a >> b;
		graph[a].push_back(b);
	}

	been.resize(N+1,false);

	for(int i=1; i<=N; i++){
		if(!been[i]) dfs(i);
	}

	been.resize(N+1,false);
	bool check;
	bool AtLeastTwo=false;
	int i=0;
	reverse(solution.begin(),solution.end());
	
	for(int place:solution){
		check=false;
		been[place]=true;
		for(int u:graph[place]){
			if(!been[u]) {cout << 0 << u << place; return 0;}
			if(i < N && u == solution[i+1]) {check=true;}
		}
		if(!check && i<N-1){AtLeastTwo=true;}
		i++;
	}
	if(AtLeastTwo) cout << "2\n";
	else cout << "1\n";
	
	for(int n:solution) cout << n << " ";
return 0;
}
SubtaskSumTestVerdictTimeMemory
base7/50
1Accepted0/01ms508 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/0194ms6060 KiB
4Wrong answer0/21ms316 KiB
5Partially correct1/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Runtime error0/161ms64000 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/33ms316 KiB
11Wrong answer0/33ms316 KiB
12Runtime error0/161ms64000 KiB
13Accepted2/23ms316 KiB
14Wrong answer0/31ms316 KiB
15Accepted1/1172ms4308 KiB
16Wrong answer0/3152ms8856 KiB
17Partially correct1/532ms7080 KiB
18Wrong answer0/1201ms10900 KiB
19Accepted2/2162ms4528 KiB
20Wrong answer0/3211ms16044 KiB
21Wrong answer0/4215ms21044 KiB
22Wrong answer0/4174ms18096 KiB