234492026-01-23 09:29:22ercseferencTestnevelés óracpp17Wrong answer 8/501.095s64000 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=1; i<=n; i++){
            for(int i:ut)cout<<i<<" ";
            cout<<endl;
            for(int i=1; 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
base8/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Time limit exceeded0/01.087s57780 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/3107ms4044 KiB
11Wrong answer0/3187ms7220 KiB
12Accepted1/13ms616 KiB
13Accepted2/23ms316 KiB
14Wrong answer0/3187ms7116 KiB
15Accepted1/1157ms4272 KiB
16Time limit exceeded0/31.077s62752 KiB
17Time limit exceeded0/51.095s64000 KiB
18Time limit exceeded0/11.07s63240 KiB
19Accepted2/2153ms4540 KiB
20Time limit exceeded0/31.021s59224 KiB
21Time limit exceeded0/41.042s60820 KiB
22Time limit exceeded0/41.062s62048 KiB