179302025-09-23 19:19:36algoproTestnevelés óracpp17Runtime error 4/501.1s21168 KiB
// UUID: eab88e1e-bbd9-4c90-a3dd-569b004be37c
#include <bits/stdc++.h>
using namespace std;

void melysegi(int i,vector<vector<int>> &matrix,vector<bool> &volt, vector<int> &sorrend, bool &ok) {
	for (int j = 0;j < matrix[i].size();j++) {
		if (!volt[matrix[i][j] - 1]) {
			volt[matrix[i][j] - 1] = true;
			melysegi(matrix[i][j] - 1,matrix,volt, sorrend, ok);
			sorrend.push_back(matrix[i][j]);
		}
		else {
			if (find(sorrend.begin(), sorrend.end(), matrix[i][j]) != sorrend.end()) {
			}
			else {
				cout << 0;
				ok = false;
			}
		}
	}
}
int main() {
	bool ok;ok = true;
	int n, k; cin >> n >> k;
	int temp,temp2;temp = 0,temp2 = 0;
	vector<vector<int>> matrix(k,vector<int>(0,0));
	for (int i = 0;i < k;i++) {
		cin >> temp >> temp2;
		matrix[temp - 1].push_back(temp2);
	}
	vector<int> sorrend(0,0);
	vector<bool> volt(n,false);
	for (int i = 0;i < n;i++) {
		if (volt[i] == false) {
			volt[i] = true;
			melysegi(i, matrix, volt, sorrend, ok);
			sorrend.push_back(i + 1);
		}
	}
	if (ok) {
		cout << 1 << endl;
		for (int i = 0;i < n;i++) {
			cout << sorrend[n - i - 1] << " ";
		}
	}
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/01ms316 KiB
2Runtime error0/01ms316 KiB
3Time limit exceeded0/01.08s8112 KiB
4Wrong answer0/21ms380 KiB
5Runtime error0/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Runtime error0/31ms316 KiB
8Accepted1/11ms316 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/33ms316 KiB
11Wrong answer0/33ms316 KiB
12Accepted1/13ms492 KiB
13Accepted2/23ms488 KiB
14Runtime error0/31ms316 KiB
15Time limit exceeded0/11.1s7640 KiB
16Time limit exceeded0/31.1s8272 KiB
17Runtime error0/51ms316 KiB
18Time limit exceeded0/11.085s9264 KiB
19Time limit exceeded0/21.092s7476 KiB
20Wrong answer0/3178ms15812 KiB
21Wrong answer0/4171ms21168 KiB
22Wrong answer0/4168ms17980 KiB