2832 | 2023-01-29 00:47:21 | VMGoJo | Rendőrségi őrjárat 2 | python3 | Runtime error 0/100 | 1.582s | 119624 KiB |
from sys import stdin, stdout
minutes:int
first_it_list:set()
second_it_list:set()
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]))
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):
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]):
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 | 11804 KiB | ||||
2 | Accepted | 17ms | 12080 KiB | ||||
subtask2 | 0/30 | ||||||
3 | Accepted | 26ms | 13076 KiB | ||||
4 | Accepted | 20ms | 13284 KiB | ||||
5 | Accepted | 27ms | 13428 KiB | ||||
6 | Accepted | 28ms | 13108 KiB | ||||
7 | Accepted | 26ms | 13452 KiB | ||||
8 | Accepted | 20ms | 13872 KiB | ||||
9 | Runtime error | 238ms | 15352 KiB | ||||
subtask3 | 0/30 | ||||||
10 | Runtime error | 587ms | 79872 KiB | ||||
11 | Runtime error | 683ms | 81248 KiB | ||||
12 | Runtime error | 694ms | 85996 KiB | ||||
13 | Runtime error | 605ms | 90096 KiB | ||||
14 | Runtime error | 704ms | 93308 KiB | ||||
subtask4 | 0/40 | ||||||
15 | Accepted | 990ms | 115624 KiB | ||||
16 | Accepted | 1.118s | 119624 KiB | ||||
17 | Time limit exceeded | 1.549s | 49144 KiB | ||||
18 | Time limit exceeded | 1.582s | 50320 KiB | ||||
19 | Time limit exceeded | 1.57s | 51436 KiB | ||||
20 | Time limit exceeded | 1.567s | 50668 KiB | ||||
21 | Time limit exceeded | 1.582s | 51844 KiB | ||||
22 | Time limit exceeded | 1.574s | 51876 KiB | ||||
23 | Accepted | 545ms | 110828 KiB | ||||
24 | Runtime error | 707ms | 94200 KiB |