28292023-01-29 00:35:44VMGoJoRendőrségi őrjárat 2python3Runtime error 0/100472ms103548 KiB
from sys import stdin, stdout

def main():
    n,m,l = map(int,stdin.readline().split())
    nodes:list[set[int]]=[]

    def addConnection(a:int,b:int):
        nodes[a].add(b)
        nodes[b].add(a)

    for i in range(n):
        nodes.append(set([i]))

    tunnels:list[list[str]]=[]
    for i in range(m):
        a,b = map(int,stdin.readline().split())
        addConnection(a,b)


    #print(nodes)
    patrols=stdin.readline().split()
    patrols = [int(i) for i in patrols]

    minutes:int=0
    first_it_list:set[int]=[0]
    second_it_list:set[int]
    found:bool=False
    #BREADTH FIRST SEARCH
    def do_layer(first_it_l:set[int]) ->set[int]:
        rt_set:set[int]=set([])
        for i in first_it_l:
            for j in nodes[i]:
                rt_set.add(j)
        return rt_set

    def check_stuff(set_in:set[int]) ->set[int]:
        global found
        #print("removing: ",patrols[(minutes-1)%len(patrols)])
        try:
            
            set_in.remove(patrols[(minutes)%len(patrols)])
        except:
            pass
        if set_in.__contains__(n-1):
            stdout.write(str(minutes))
            found=True
        else:
            return set_in

    def do_min():
        global minutes, first_it_list,second_it_list
        minutes+=1
        second_it_list=check_stuff(do_layer(first_it_list))
        #print(second_it_list)
        if not found:
            first_it_list=second_it_list
            do_min()
    do_min()
main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error18ms12316 KiB
2Runtime error17ms12696 KiB
subtask20/30
3Runtime error19ms13288 KiB
4Runtime error19ms13576 KiB
5Runtime error19ms13940 KiB
6Runtime error19ms13980 KiB
7Runtime error20ms14088 KiB
8Runtime error19ms14028 KiB
9Runtime error19ms14536 KiB
subtask30/30
10Runtime error356ms79260 KiB
11Runtime error352ms81476 KiB
12Runtime error455ms85808 KiB
13Runtime error465ms90864 KiB
14Runtime error375ms94600 KiB
subtask40/40
15Runtime error467ms97608 KiB
16Runtime error388ms103548 KiB
17Runtime error382ms100848 KiB
18Runtime error470ms100868 KiB
19Runtime error381ms100988 KiB
20Runtime error472ms101192 KiB
21Runtime error400ms101400 KiB
22Runtime error402ms101380 KiB
23Runtime error397ms97424 KiB
24Runtime error469ms94768 KiB