86482024-01-24 21:09:48KezdőKerékpártúra (50 pont)python3Time limit exceeded 24/50486ms23924 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)
    for x in tura:
        stdout.write(str(x)+' ')
main()
SubtaskSumTestVerdictTimeMemory
base24/50
1Accepted0/018ms11480 KiB
2Time limit exceeded0/0485ms7988 KiB
3Accepted2/217ms11900 KiB
4Accepted2/217ms11972 KiB
5Accepted2/217ms12116 KiB
6Accepted2/217ms12356 KiB
7Accepted2/219ms12484 KiB
8Accepted2/226ms13496 KiB
9Accepted2/223ms13120 KiB
10Accepted2/224ms13260 KiB
11Accepted2/259ms13980 KiB
12Accepted2/2148ms15580 KiB
13Accepted2/2123ms16260 KiB
14Accepted2/2310ms18584 KiB
15Time limit exceeded0/3472ms10872 KiB
16Time limit exceeded0/4476ms11348 KiB
17Time limit exceeded0/4486ms13304 KiB
18Time limit exceeded0/3460ms12368 KiB
19Time limit exceeded0/3472ms11540 KiB
20Time limit exceeded0/3479ms21904 KiB
21Time limit exceeded0/3458ms23588 KiB
22Time limit exceeded0/3456ms23924 KiB