86492024-01-24 21:56:55KezdőKerékpártúra (50 pont)python3Time limit exceeded 24/50500ms24488 KiB
from sys import stdin,stdout

def main():
    N,M,K = [int(i) for i in input().split()]
    oda = [[] for i in range(N+1)]
    vissza = [[] for i in range(N+1)]
    for i in range(M):
        k,v = [int(i) for i in stdin.readline().split()]
        oda[k].append(v)
        vissza[v].append(k)

    def BSF(S,gr):
        sor = [S]
        volt = [S]
        while sor != []:
            P = sor.pop(0)
            for x in gr[P]:
                if x not in volt:
                    volt.append(x)
                    sor.append(x)
        return volt

    A = BSF(K,oda)
    B = BSF(K,vissza)
    tura = oda[K]
    db = len(tura)
    for x in B:
        for y in oda[x]:
            if y != K and y not in tura:
                tura.append(y)
                db += 1

    print(db)
    print(*tura)

main()
SubtaskSumTestVerdictTimeMemory
base24/50
1Accepted0/017ms11296 KiB
2Time limit exceeded0/0500ms7796 KiB
3Accepted2/217ms11780 KiB
4Accepted2/218ms11860 KiB
5Accepted2/217ms11820 KiB
6Accepted2/219ms12124 KiB
7Accepted2/219ms12332 KiB
8Accepted2/225ms12380 KiB
9Accepted2/223ms12772 KiB
10Accepted2/225ms13020 KiB
11Accepted2/259ms13792 KiB
12Accepted2/2149ms15776 KiB
13Accepted2/2125ms16072 KiB
14Accepted2/2310ms18740 KiB
15Time limit exceeded0/3465ms11100 KiB
16Time limit exceeded0/4463ms11288 KiB
17Time limit exceeded0/4460ms13536 KiB
18Time limit exceeded0/3460ms12984 KiB
19Time limit exceeded0/3463ms12380 KiB
20Time limit exceeded0/3472ms22696 KiB
21Time limit exceeded0/3488ms24024 KiB
22Time limit exceeded0/3472ms24488 KiB