2830 | 2023-01-29 00:42:56 | VMGoJo | Rendőrségi őrjárat 2 | python3 | Runtime error 0/100 | 1.582s | 119436 KiB |
from sys import stdin, stdout
minutes:int
first_it_list:set[int]
second_it_list:set[int]
found:bool
def main():
n,m,l = map(int,stdin.readline().split())
nodes=[]
def addConnection(a:int,b:int):
nodes[a].add(b)
nodes[b].add(a)
for i in range(n):
nodes.append(set([i]))
tunnels=[]
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]
global minutes,first_it_list,second_it_list,found
minutes=0
first_it_list=[0]
found=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
def check_stuff(set_in:set[int]) ->set[int]:
global found
#print("removing: ",patrols[(minutes-1)%len(patrols)])
try:
set_in.remove(patrols[(minutes)%len(patrols)])
except:
pass
if set_in.__contains__(n-1):
stdout.write(str(minutes))
found=True
else:
return set_in
def do_min():
global minutes, first_it_list,second_it_list
minutes+=1
second_it_list=check_stuff(do_layer(first_it_list))
#print(second_it_list)
if not found:
first_it_list=second_it_list
do_min()
do_min()
main()
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 18ms | 11668 KiB | ||||
2 | Accepted | 17ms | 12076 KiB | ||||
subtask2 | 0/30 | ||||||
3 | Accepted | 25ms | 13084 KiB | ||||
4 | Accepted | 19ms | 13288 KiB | ||||
5 | Accepted | 27ms | 13148 KiB | ||||
6 | Accepted | 28ms | 13396 KiB | ||||
7 | Accepted | 25ms | 13512 KiB | ||||
8 | Accepted | 19ms | 13376 KiB | ||||
9 | Runtime error | 234ms | 15312 KiB | ||||
subtask3 | 0/30 | ||||||
10 | Runtime error | 707ms | 79600 KiB | ||||
11 | Runtime error | 606ms | 81044 KiB | ||||
12 | Runtime error | 616ms | 85020 KiB | ||||
13 | Runtime error | 619ms | 89568 KiB | ||||
14 | Runtime error | 628ms | 93024 KiB | ||||
subtask4 | 0/40 | ||||||
15 | Accepted | 1s | 117304 KiB | ||||
16 | Accepted | 980ms | 119436 KiB | ||||
17 | Time limit exceeded | 1.577s | 49116 KiB | ||||
18 | Time limit exceeded | 1.575s | 50508 KiB | ||||
19 | Time limit exceeded | 1.55s | 51600 KiB | ||||
20 | Time limit exceeded | 1.582s | 51608 KiB | ||||
21 | Time limit exceeded | 1.582s | 51904 KiB | ||||
22 | Time limit exceeded | 1.559s | 51972 KiB | ||||
23 | Accepted | 460ms | 111248 KiB | ||||
24 | Runtime error | 711ms | 94376 KiB |