234522026-01-23 09:31:50ercseferencTestnevelés óracpp17Wrong answer 9/50237ms13352 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream f("szamok.txt");
    int n,m; cin>>n>>m;
    vector<vector<int>>a(n+1);
    vector<int>t(n+1,0);
    for(int i=0; i<m; i++){
        int x,y; cin>>x>>y;
        a[x].push_back(y); t[y]++;}
    queue<int>q;
    int vand=-1;
    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;
    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[vand+1];
            else if(i==vand+1)cout<<ut[vand];
            else cout<<ut[i];}}
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base9/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms512 KiB
3Wrong answer0/0196ms7216 KiB
4Wrong answer0/21ms316 KiB
5Partially correct1/31ms332 KiB
6Wrong answer0/31ms500 KiB
7Wrong answer0/31ms316 KiB
8Accepted1/12ms316 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/33ms316 KiB
11Wrong answer0/33ms316 KiB
12Accepted1/12ms316 KiB
13Accepted2/23ms432 KiB
14Wrong answer0/32ms316 KiB
15Accepted1/1172ms4340 KiB
16Wrong answer0/3151ms9672 KiB
17Partially correct1/550ms9896 KiB
18Wrong answer0/1237ms13352 KiB
19Accepted2/2170ms4528 KiB
20Wrong answer0/3212ms11436 KiB
21Wrong answer0/4214ms11440 KiB
22Wrong answer0/4195ms11436 KiB