28482023-01-29 20:08:52VMGoJoRendőrségi őrjárat 2python3Time limit exceeded 30/1001.601s117268 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:set[int]=[0]
    #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]:
                if j!=cop_loc:
                    rt_set.add(j)
        return rt_set
    while not first_it_list.__contains__(n-1):
        minutes+=1
        cop_loc=patrols[minutes%len(patrols)]
        first_it_list=do_layer(first_it_list)
    stdout.write(str(minutes))

main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted18ms11488 KiB
2Accepted17ms11368 KiB
subtask230/30
3Accepted26ms12904 KiB
4Accepted19ms13224 KiB
5Accepted28ms13312 KiB
6Accepted29ms13628 KiB
7Accepted26ms13884 KiB
8Accepted19ms14048 KiB
9Accepted279ms13976 KiB
subtask30/30
10Time limit exceeded1.57s38172 KiB
11Time limit exceeded1.601s39160 KiB
12Time limit exceeded1.557s41352 KiB
13Time limit exceeded1.57s43832 KiB
14Time limit exceeded1.554s45872 KiB
subtask40/40
15Accepted949ms115468 KiB
16Accepted866ms117268 KiB
17Time limit exceeded1.577s49156 KiB
18Time limit exceeded1.585s51392 KiB
19Time limit exceeded1.557s51436 KiB
20Time limit exceeded1.57s51664 KiB
21Time limit exceeded1.562s51732 KiB
22Time limit exceeded1.559s51804 KiB
23Accepted541ms112168 KiB
24Time limit exceeded1.582s46496 KiB