89932024-02-11 00:12:04xxxTestnevelés óracpp17Wrong answer 2/506ms12660 KiB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 2 * (1e5 + 1);

vector<vector<int> > adj(mxN);
int in[mxN];
bool vis[mxN], rev[mxN];
bool ex;


void dfs (int u) {
	if (ex) {
		return;
	}
	vis[u] = true;
	rev[u] = true;

	for(int x : adj[u]) {
		if (rev[x]) {
			cout << "0\n";
			ex = true;
			return;
		} else if (!vis[x]) {
			dfs(x);
		}
	}

	rev[u] = false;

}


int main() {
    cout << 0 << endl;
    return 0;
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		in[y]++;
	}
	dfs(1);
	if (ex) {
        return 0;
	}

	vector<int> top;
	queue<int> q;

	for(int i = 1; i <= n; i++) {
		if (in[i] == 0) {
			top.push_back(i);
			q.push(i);
			vis[i] = 1;
		}
	}
	int ind;
	bool flag = false;
	if(top.size() > 1) {
        flag = true;
        ind = 1;
	}

	while(!q.empty()) {
        int v = q.front();
        q.pop();
        int cnt = 0;
        for(int u : adj[v]) {
            in[u]--;
            if (in[u] == 0) {
                q.push(u);
                top.push_back(u);
                cnt++;
            }
        }
        if (cnt >= 2) {
            flag = true;
            ind = top.size();
        }
	}

    if (flag) {
        cout << "2\n";
        for(int x : top) {
            cout << x << ' ';
        }
        cout << endl;
        swap(top[ind], top[ind-1]);
        for(int x : top) {
            cout << x << ' ';
        }
        cout << endl;
    } else {
        cout << "1\n";
        for(int x : top) {
            cout << x << ' ';
        }
        cout << endl;
    }
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Wrong answer0/06ms11092 KiB
2Wrong answer0/06ms11288 KiB
3Wrong answer0/06ms11700 KiB
4Wrong answer0/26ms11596 KiB
5Wrong answer0/34ms11600 KiB
6Wrong answer0/36ms11892 KiB
7Wrong answer0/36ms11852 KiB
8Accepted1/16ms11888 KiB
9Wrong answer0/36ms12084 KiB
10Wrong answer0/36ms12184 KiB
11Wrong answer0/36ms12296 KiB
12Accepted1/16ms12376 KiB
13Wrong answer0/26ms12388 KiB
14Wrong answer0/36ms12660 KiB
15Wrong answer0/16ms12540 KiB
16Wrong answer0/36ms12476 KiB
17Wrong answer0/56ms12464 KiB
18Wrong answer0/16ms12592 KiB
19Wrong answer0/26ms12528 KiB
20Wrong answer0/36ms12536 KiB
21Wrong answer0/46ms12536 KiB
22Wrong answer0/46ms12532 KiB