91652024-02-16 18:43:04NagyLeoTestnevelés órapython3Wrong answer 46/50906ms85412 KiB
def solv():
    N, K = map(int, input().split())
    graph = [[] for i in range(N + 1)]
    indeg = [0] * (N + 1)

    for i in range(K):
        a, b = map(int, input().split())
        graph[a].append(b)
        indeg[b] += 1

    zero = []
    #   a --> b --> 2 <-- c
    #     \-> d
    for i in range(1, N + 1):
        if indeg[i] == 0:
            zero.append(i)
    # print(parents)
    result = [zero[:]]
    seen = zero[:]
    while zero:
        tmp = []
        for i in zero:
            for j in graph[i]:
                indeg[j] -= 1
                if indeg[j] == 0:
                    tmp.append(j)
                    seen.append(j)
        if tmp:
            result.append(tmp[:])
        zero = tmp

    # print(result,graph)
    if len(seen) != N:
        print("0")
        return
    if len(result) == N:
        print("1")
        print(*result)
    else:
        # result=[ [1,2,3], [4,5]]
        print("2")
        for i in result:
            print(*i, end=" ")
        print()
        for i in result:
            print(*i[::-1], end=" ")


solv()
SubtaskSumTestVerdictTimeMemory
base46/50
1Wrong answer0/017ms11684 KiB
2Accepted0/018ms11752 KiB
3Accepted0/0610ms50936 KiB
4Accepted2/217ms12140 KiB
5Accepted3/317ms12416 KiB
6Accepted3/317ms12768 KiB
7Accepted3/318ms12700 KiB
8Accepted1/117ms13096 KiB
9Accepted3/318ms13212 KiB
10Accepted3/325ms13724 KiB
11Accepted3/326ms14072 KiB
12Accepted1/124ms13920 KiB
13Wrong answer0/227ms14280 KiB
14Accepted3/320ms13992 KiB
15Wrong answer0/1564ms48700 KiB
16Accepted3/3537ms58788 KiB
17Accepted5/5268ms73548 KiB
18Accepted1/1809ms85412 KiB
19Partially correct1/2624ms50952 KiB
20Accepted3/3890ms84892 KiB
21Accepted4/4906ms84948 KiB
22Accepted4/4892ms84944 KiB