84982024-01-19 12:21:05birozsKerékpártúra (50 pont)python3Time limit exceeded 41/50476ms45820 KiB
N,M,K = map(int,input().split())
el = []
fel = []
for i in range(N+1):
    el.append([])
    fel.append([])
for i in range(M):
    tol,ig = map(int,input().split())
    el[tol].append(ig)
    fel[ig].append(tol)

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
base41/50
1Accepted0/017ms11252 KiB
2Accepted0/085ms19112 KiB
3Accepted2/217ms11732 KiB
4Accepted2/217ms12020 KiB
5Accepted2/217ms11964 KiB
6Accepted2/217ms12216 KiB
7Accepted2/218ms12188 KiB
8Accepted2/225ms12512 KiB
9Accepted2/226ms12732 KiB
10Accepted2/228ms12696 KiB
11Accepted2/234ms13532 KiB
12Accepted2/261ms15500 KiB
13Accepted2/261ms15508 KiB
14Accepted2/2104ms18012 KiB
15Accepted3/3136ms24040 KiB
16Accepted4/4152ms26028 KiB
17Accepted4/4201ms29984 KiB
18Accepted3/3195ms28696 KiB
19Accepted3/3166ms27336 KiB
20Time limit exceeded0/3451ms45820 KiB
21Time limit exceeded0/3476ms23728 KiB
22Time limit exceeded0/3465ms24716 KiB