28492023-01-29 20:21:56VMGoJoRendőrségi őrjárat 2python3Time limit exceeded 30/1001.582s103564 KiB
from sys import stdin, stdout
def main():
    n,m,l = map(int,stdin.readline().split())
    nodes:list[set[int]]=[]

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

    for i in range(m):
        a,b = map(int,stdin.readline().split())
        nodes[a].add(b)
        nodes[b].add(a)


    #print(nodes)
    patrols=stdin.readline().split()
    patrols = [int(i) for i in patrols]
    cop_loc:int=patrols[0]
    minutes:int=0
    first_it_list:list[bool]=[False]*n
    first_it_list[0]=True
    #BREADTH FIRST SEARCH
    def do_layer(first_it_l:list[bool]) ->list[bool]:
        rt_set:list[bool]=[False]*n
        for i in range(n):
            if first_it_list[i]==True:
                for j in nodes[i]:
                    rt_set[j]=True
        return rt_set
    while not first_it_list[n-1]==True:
        minutes+=1
        cop_loc=patrols[minutes%len(patrols)]
        first_it_list=do_layer(first_it_list)
        first_it_list[cop_loc]=False
    stdout.write(str(minutes))

main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted17ms11348 KiB
2Accepted17ms11496 KiB
subtask230/30
3Accepted24ms12776 KiB
4Accepted19ms12884 KiB
5Accepted26ms13132 KiB
6Accepted28ms13304 KiB
7Accepted24ms13684 KiB
8Accepted19ms13896 KiB
9Accepted223ms13816 KiB
subtask30/30
10Time limit exceeded1.577s39572 KiB
11Time limit exceeded1.554s40824 KiB
12Time limit exceeded1.569s43012 KiB
13Time limit exceeded1.562s44176 KiB
14Time limit exceeded1.574s45792 KiB
subtask40/40
15Accepted893ms98396 KiB
16Accepted713ms103564 KiB
17Time limit exceeded1.57s49780 KiB
18Time limit exceeded1.57s49804 KiB
19Time limit exceeded1.578s49956 KiB
20Time limit exceeded1.57s49992 KiB
21Time limit exceeded1.562s50100 KiB
22Time limit exceeded1.577s49992 KiB
23Accepted402ms97480 KiB
24Time limit exceeded1.582s46432 KiB