28462023-01-29 19:57:42VMGoJoRendőrségi őrjárat 2python3Time limit exceeded 30/1001.59s120332 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]
    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
    while not first_it_list.__contains__(n-1):
        minutes+=1
        first_it_list=do_layer(first_it_list)
        first_it_list=first_it_list.difference(set([patrols[minutes%len(patrols)]]))
    stdout.write(str(minutes))

main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted18ms11708 KiB
2Accepted17ms11904 KiB
subtask230/30
3Accepted25ms13060 KiB
4Accepted19ms13516 KiB
5Accepted28ms13356 KiB
6Accepted28ms13748 KiB
7Accepted25ms13856 KiB
8Accepted19ms13956 KiB
9Accepted243ms14436 KiB
subtask30/30
10Time limit exceeded1.57s38468 KiB
11Time limit exceeded1.574s39416 KiB
12Time limit exceeded1.572s41400 KiB
13Time limit exceeded1.588s44080 KiB
14Time limit exceeded1.585s46072 KiB
subtask40/40
15Accepted939ms116292 KiB
16Accepted728ms120332 KiB
17Time limit exceeded1.559s49816 KiB
18Time limit exceeded1.59s50872 KiB
19Time limit exceeded1.55s49640 KiB
20Time limit exceeded1.57s50696 KiB
21Time limit exceeded1.562s50656 KiB
22Time limit exceeded1.567s52828 KiB
23Accepted412ms111000 KiB
24Time limit exceeded1.577s46688 KiB