179802025-09-24 18:19:05algoproTestnevelés óracpp17Wrong answer 9/50216ms18864 KiB
// UUID: 46bbc290-bf82-400b-8923-5b7d724bdecb
#include <bits/stdc++.h>
using namespace std;

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

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


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.assign(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; 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
base9/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/0192ms6060 KiB
4Wrong answer0/21ms316 KiB
5Partially correct1/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Accepted1/11ms512 KiB
9Wrong answer0/31ms556 KiB
10Wrong answer0/33ms316 KiB
11Wrong answer0/33ms316 KiB
12Accepted1/13ms316 KiB
13Accepted2/23ms316 KiB
14Wrong answer0/32ms508 KiB
15Accepted1/1165ms4344 KiB
16Wrong answer0/3134ms8880 KiB
17Partially correct1/534ms7320 KiB
18Wrong answer0/1216ms10792 KiB
19Accepted2/2159ms4528 KiB
20Wrong answer0/3206ms14904 KiB
21Wrong answer0/4181ms18864 KiB
22Wrong answer0/4186ms16384 KiB