89542024-02-07 18:07:56NagyLeoA lehető legkevesebb metróval utazás (40 pont)python3Wrong answer 2/4020ms13844 KiB
def main3():
    N, M, Dep, Arr = map(int, input().split())
    metro = []
    Dep_index = set()
    Arr_index = set()
    for i in range(N):
        asd = list(map(int, input().split()))

        metro.append(set(asd[1:]))
        if Dep in metro[i]:
            Dep_index.add(i)
        if Arr in metro[i]:
            Arr_index.add(i)
        if i in Arr_index and i in Dep_index:
            print(1)
            print(i+1)
            return

    graph={}

    for i in range(N-1):
        for j in range(i+1, N):
            if not metro[i].isdisjoint(metro[j]):
                try:
                    graph[i].append(j)
                except:
                    graph[i] = [j]
                try:
                    graph[j].append(i)
                except:
                    graph[j] = [i]

    touched = Dep_index.copy()
    current_res = [0]*N
    for i in Dep_index:
        current_res[i]=[i]
    while Dep_index:
        tmp=[]
        for i in Dep_index:
            if i not in graph:
                continue
            for j in graph[i]:
                if j not in touched:
                    tmp.append(j)
                    touched.add(j)
                    current_res[j]=current_res[i]+[j]
                    if j in Arr_index:
                        print(len(current_res[j]))
                        [print(x+1, end=" ") for x in current_res[j]]
                        return
        Dep_index=tmp

    print("-1")

def main4():
    print("-1")

main4()
SubtaskSumTestVerdictTimeMemory
base2/40
1Wrong answer0/018ms11440 KiB
2Wrong answer0/018ms11648 KiB
3Wrong answer0/218ms11720 KiB
4Wrong answer0/218ms12100 KiB
5Wrong answer0/220ms12224 KiB
6Accepted2/218ms12220 KiB
7Wrong answer0/218ms12528 KiB
8Wrong answer0/218ms12540 KiB
9Wrong answer0/217ms12624 KiB
10Wrong answer0/217ms12660 KiB
11Wrong answer0/218ms12776 KiB
12Wrong answer0/217ms12912 KiB
13Wrong answer0/217ms12856 KiB
14Wrong answer0/217ms13216 KiB
15Wrong answer0/217ms13404 KiB
16Wrong answer0/218ms13328 KiB
17Wrong answer0/217ms13264 KiB
18Wrong answer0/217ms13316 KiB
19Wrong answer0/217ms13156 KiB
20Wrong answer0/218ms13564 KiB
21Wrong answer0/219ms13844 KiB
22Wrong answer0/218ms13660 KiB