84972024-01-19 12:19:13birozsKerékpártúra (50 pont)python3Runtime error 0/5018ms14180 KiB
'''
N,M,K = map(int,input().split())
el = []
for i in range(M):
    tol,ig = map(int,input().split())
    el.append([tol,ig,0,0])
'''
be = open("be2.txt")
N,M,K = map(int,be.readline().split())
el = []
fel = []
for i in range(N+1):
    el.append([])
    fel.append([])
for i in range(M):
    tol,ig = map(int,be.readline().split())
    el[tol].append(ig)
    fel[ig].append(tol)
be.close()
sor = [K]
szin = [0] * (N+1)
szin[K] = 1
while len(sor)>0:
    AktCsucs = sor[-1]
    szin[AktCsucs] = 2
    sor.pop()
    for j in fel[AktCsucs]:
        if szin[j] == 0:
            sor.append(j)
            szin[j] = 1
halmaz = set()
for i in range(1,N+1):
    if szin[i] != 0:
        if i != K:
            halmaz.add(i)
        for x in el[i]:
            if x != K:
                halmaz.add(x)
print(len(halmaz))
for x in halmaz:
    print(x,end=" ")










SubtaskSumTestVerdictTimeMemory
base0/50
1Runtime error0/018ms11676 KiB
2Runtime error0/017ms11836 KiB
3Runtime error0/217ms12232 KiB
4Runtime error0/217ms12300 KiB
5Runtime error0/217ms12264 KiB
6Runtime error0/217ms12396 KiB
7Runtime error0/217ms12544 KiB
8Runtime error0/217ms12532 KiB
9Runtime error0/217ms12508 KiB
10Runtime error0/217ms12972 KiB
11Runtime error0/217ms13136 KiB
12Runtime error0/217ms13176 KiB
13Runtime error0/217ms13540 KiB
14Runtime error0/217ms13684 KiB
15Runtime error0/317ms13960 KiB
16Runtime error0/417ms13688 KiB
17Runtime error0/418ms13636 KiB
18Runtime error0/317ms13712 KiB
19Runtime error0/317ms13928 KiB
20Runtime error0/317ms14104 KiB
21Runtime error0/317ms13852 KiB
22Runtime error0/318ms14180 KiB