234532026-01-23 09:37:00ercseferencTestnevelés óracpp17Wrong answer 9/50221ms13340 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream f("szamok.txt");
    int n,m; cin>>n>>m;
    vector<int>a[n+1];
    vector<int>t(n+1);
    for(int i=0; i<m; i++){
        int x,y; cin>>x>>y;
        a[x].push_back(y); t[y]++;}
    int vand=-1;
    queue<int>q;
    for(int i=1; i<=n; i++){
        if(t[i]==0)q.push(i);}
    vector<int>ut;
    while(!q.empty()){
        int x=q.front();
        q.pop();
        ut.push_back(x);
        if(!q.empty())vand=ut.size()-1;
        for(int i:a[x]){
            t[i]--;
            if(t[i]==0)q.push(i);}
        }
    if(ut.size()!=n)cout<<0<<endl;
    else if(vand==-1){
        cout<<1<<endl;
        for(int i:ut)cout<<i<<" ";
        }
    else {
        cout<<2<<endl;
        for(int i:ut)cout<<i<<" ";
        cout<<endl;
        for(int i=0; i<n; i++){
            if(i==vand)cout<<ut[i+1];
            else if(i==vand+1)cout<<ut[i-1];
            else cout<<ut[i];}}
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base9/50
1Accepted0/01ms508 KiB
2Wrong answer0/01ms508 KiB
3Wrong answer0/0188ms7096 KiB
4Wrong answer0/21ms316 KiB
5Partially correct1/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Accepted1/11ms316 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/33ms336 KiB
11Wrong answer0/33ms316 KiB
12Accepted1/13ms316 KiB
13Accepted2/23ms620 KiB
14Wrong answer0/32ms316 KiB
15Accepted1/1164ms4460 KiB
16Wrong answer0/3150ms9780 KiB
17Partially correct1/550ms9896 KiB
18Wrong answer0/1221ms13340 KiB
19Accepted2/2165ms4528 KiB
20Wrong answer0/3203ms11436 KiB
21Wrong answer0/4194ms11516 KiB
22Wrong answer0/4175ms11436 KiB