178942025-09-22 17:53:59algoproTestnevelés órapypy3Runtime error 30/50474ms64000 KiB
# UUID: 8e2e1404-cc24-4b01-ba83-baca373c1452
n,k=map(int,input().split())
l=[[] for _ in range(n+1)]
be=[0]*(n+1)
for i in range(k):
    x=list(map(int,input().split()))
    l[x[0]].append(x[1])
    be[x[1]]+=1
#print(l)
munka=[]
volt=set()
volt2=set()
m=0
mode=1
swap=-1
for i in range(1,n+1):
    if be[i]==0:
        munka.append(i)
        volt.add(i)
for _ in range(n):
    #print(munka,be)
    if len(munka)<=m:
        mode=0
        break
    x=munka[m]
    #print(x)
    volt2.add(x)
    m+=1
    for i in l[x]:
        #print(i,volt2)
        if i not in volt:
            be[i]-=1
            if be[i]==0:
                munka.append(i)
                volt.add(i)

if mode==1:
    for i in range(n-1):
        if munka[i+1] not in l[munka[i]]:
            mode=2
            swap=i
            break

print(mode)
for i in range(mode):
    for j in range(len(munka)):
        if i==1 and  j==swap:
            print(munka[j+1],end=" ")
        elif i==1 and j==swap+1:
            print(munka[j-1],end=" ")
        else:
            print(munka[j],end=" ")
    print()
        
SubtaskSumTestVerdictTimeMemory
base30/50
1Accepted0/039ms19692 KiB
2Accepted0/039ms19684 KiB
3Runtime error0/0474ms64000 KiB
4Accepted2/243ms19688 KiB
5Accepted3/345ms19656 KiB
6Accepted3/345ms19956 KiB
7Accepted3/339ms19752 KiB
8Accepted1/139ms19680 KiB
9Accepted3/343ms19784 KiB
10Accepted3/397ms24020 KiB
11Accepted3/3109ms24040 KiB
12Accepted1/190ms23272 KiB
13Accepted2/294ms23176 KiB
14Accepted3/376ms22248 KiB
15Accepted1/1437ms47736 KiB
16Runtime error0/3301ms64000 KiB
17Runtime error0/593ms64000 KiB
18Runtime error0/1305ms64000 KiB
19Accepted2/2423ms50152 KiB
20Runtime error0/3312ms64000 KiB
21Runtime error0/4372ms64000 KiB
22Runtime error0/4303ms64000 KiB