179822025-09-24 18:19:33algoproTestnevelés óracpp17Wrong answer 9/50238ms14844 KiB
// UUID: 9256c001-ea02-451b-9ef1-210f86364e6d
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,k;cin >> n >>k;
	vector<int>a(n+1,0);
	vector<vector<int>>b(n+1);
	for(int i = 0; i < k;i++){
		int u,p; cin >> u >> p;
		b[u].push_back(p);
		a[p]++;
	}
	queue<int>q;
	vector<vector<int>>ki(2);
	for(int i = 1; i <= n;i++){
		if(a[i] == 0){
			q.push(i);
		}
	}
	bool tobb = false;
	while(!q.empty()){
		int most = q.front();
		q.pop();
		if(tobb == false&&q.size()>1){
			tobb = true;
			ki[1] = ki[0];
			ki[0].push_back(most);
			for(int i : b[most]){
			a[i]--;
				if(a[i] == 0){
					q.push(i);
				}
			}
			most=q.front();
			q.pop();
			ki[1].push_back(most);
			ki[1].push_back(ki[0][ki[0].size()-1]);

		}
		ki[0].push_back(most);
		for(int i : b[most]){
			a[i]--;
			if(a[i] == 0){
				q.push(i);
			}
		}
	}
	if(ki[0].size() != n){
		cout << "0";
		return 0;
	}
	
	if(tobb){
		for(int i = ki[1].size()-1; i < n;i++){
			ki[1].push_back(ki[0][i]);
		}
		cout << "2\n";
		for(int i = 0; i < n;i++){
			cout << ki[0][i] << " ";
		}
		cout << "\n";
		for(int i = 0; i < n;i++){
			cout << ki[1][i] << " ";
		}
	}else{
		cout << "1\n";
		for(int i = 0; i < n;i++){
			cout << ki[0][i] << " ";
		}
	}

}
SubtaskSumTestVerdictTimeMemory
base9/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/0186ms7508 KiB
4Wrong answer0/21ms316 KiB
5Partially correct1/31ms556 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Accepted1/11ms316 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/33ms316 KiB
11Wrong answer0/33ms316 KiB
12Accepted1/13ms316 KiB
13Accepted2/23ms316 KiB
14Wrong answer0/32ms316 KiB
15Accepted1/1158ms4300 KiB
16Wrong answer0/3140ms10220 KiB
17Partially correct1/559ms11284 KiB
18Wrong answer0/1238ms14844 KiB
19Accepted2/2151ms4528 KiB
20Wrong answer0/3158ms10820 KiB
21Wrong answer0/4180ms10668 KiB
22Wrong answer0/4158ms10680 KiB