2848 | 2023-01-29 20:08:52 | VMGoJo | Rendőrségi őrjárat 2 | python3 | Time limit exceeded 30/100 | 1.601s | 117268 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()
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 18ms | 11488 KiB | ||||
2 | Accepted | 17ms | 11368 KiB | ||||
subtask2 | 30/30 | ||||||
3 | Accepted | 26ms | 12904 KiB | ||||
4 | Accepted | 19ms | 13224 KiB | ||||
5 | Accepted | 28ms | 13312 KiB | ||||
6 | Accepted | 29ms | 13628 KiB | ||||
7 | Accepted | 26ms | 13884 KiB | ||||
8 | Accepted | 19ms | 14048 KiB | ||||
9 | Accepted | 279ms | 13976 KiB | ||||
subtask3 | 0/30 | ||||||
10 | Time limit exceeded | 1.57s | 38172 KiB | ||||
11 | Time limit exceeded | 1.601s | 39160 KiB | ||||
12 | Time limit exceeded | 1.557s | 41352 KiB | ||||
13 | Time limit exceeded | 1.57s | 43832 KiB | ||||
14 | Time limit exceeded | 1.554s | 45872 KiB | ||||
subtask4 | 0/40 | ||||||
15 | Accepted | 949ms | 115468 KiB | ||||
16 | Accepted | 866ms | 117268 KiB | ||||
17 | Time limit exceeded | 1.577s | 49156 KiB | ||||
18 | Time limit exceeded | 1.585s | 51392 KiB | ||||
19 | Time limit exceeded | 1.557s | 51436 KiB | ||||
20 | Time limit exceeded | 1.57s | 51664 KiB | ||||
21 | Time limit exceeded | 1.562s | 51732 KiB | ||||
22 | Time limit exceeded | 1.559s | 51804 KiB | ||||
23 | Accepted | 541ms | 112168 KiB | ||||
24 | Time limit exceeded | 1.582s | 46496 KiB |