28302023-01-29 00:42:56VMGoJoRendőrségi őrjárat 2python3Runtime error 0/1001.582s119436 KiB
from sys import stdin, stdout

minutes:int
first_it_list:set[int]
second_it_list:set[int]
found:bool
def main():
    n,m,l = map(int,stdin.readline().split())
    nodes=[]

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

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

    tunnels=[]
    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]
    global minutes,first_it_list,second_it_list,found
    minutes=0
    first_it_list=[0]
    found=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
1Accepted18ms11668 KiB
2Accepted17ms12076 KiB
subtask20/30
3Accepted25ms13084 KiB
4Accepted19ms13288 KiB
5Accepted27ms13148 KiB
6Accepted28ms13396 KiB
7Accepted25ms13512 KiB
8Accepted19ms13376 KiB
9Runtime error234ms15312 KiB
subtask30/30
10Runtime error707ms79600 KiB
11Runtime error606ms81044 KiB
12Runtime error616ms85020 KiB
13Runtime error619ms89568 KiB
14Runtime error628ms93024 KiB
subtask40/40
15Accepted1s117304 KiB
16Accepted980ms119436 KiB
17Time limit exceeded1.577s49116 KiB
18Time limit exceeded1.575s50508 KiB
19Time limit exceeded1.55s51600 KiB
20Time limit exceeded1.582s51608 KiB
21Time limit exceeded1.582s51904 KiB
22Time limit exceeded1.559s51972 KiB
23Accepted460ms111248 KiB
24Runtime error711ms94376 KiB