2849 | 2023-01-29 20:21:56 | VMGoJo | Rendőrségi őrjárat 2 | python3 | Time limit exceeded 30/100 | 1.582s | 103564 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()
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 17ms | 11348 KiB | ||||
2 | Accepted | 17ms | 11496 KiB | ||||
subtask2 | 30/30 | ||||||
3 | Accepted | 24ms | 12776 KiB | ||||
4 | Accepted | 19ms | 12884 KiB | ||||
5 | Accepted | 26ms | 13132 KiB | ||||
6 | Accepted | 28ms | 13304 KiB | ||||
7 | Accepted | 24ms | 13684 KiB | ||||
8 | Accepted | 19ms | 13896 KiB | ||||
9 | Accepted | 223ms | 13816 KiB | ||||
subtask3 | 0/30 | ||||||
10 | Time limit exceeded | 1.577s | 39572 KiB | ||||
11 | Time limit exceeded | 1.554s | 40824 KiB | ||||
12 | Time limit exceeded | 1.569s | 43012 KiB | ||||
13 | Time limit exceeded | 1.562s | 44176 KiB | ||||
14 | Time limit exceeded | 1.574s | 45792 KiB | ||||
subtask4 | 0/40 | ||||||
15 | Accepted | 893ms | 98396 KiB | ||||
16 | Accepted | 713ms | 103564 KiB | ||||
17 | Time limit exceeded | 1.57s | 49780 KiB | ||||
18 | Time limit exceeded | 1.57s | 49804 KiB | ||||
19 | Time limit exceeded | 1.578s | 49956 KiB | ||||
20 | Time limit exceeded | 1.57s | 49992 KiB | ||||
21 | Time limit exceeded | 1.562s | 50100 KiB | ||||
22 | Time limit exceeded | 1.577s | 49992 KiB | ||||
23 | Accepted | 402ms | 97480 KiB | ||||
24 | Time limit exceeded | 1.582s | 46432 KiB |