2846 | 2023-01-29 19:57:42 | VMGoJo | Rendőrségi őrjárat 2 | python3 | Time limit exceeded 30/100 | 1.59s | 120332 KiB |
from sys import stdin, stdout
def main():
n,m,l = map(int,stdin.readline().split())
nodes:list[set[int]]=[]
def addConnection(a:int,b:int):
nodes[a].add(b)
nodes[b].add(a)
for i in range(n):
nodes.append(set([i]))
tunnels:list[list[str]]=[]
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]
minutes:int=0
first_it_list:set[int]=[0]
found:bool=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
while not first_it_list.__contains__(n-1):
minutes+=1
first_it_list=do_layer(first_it_list)
first_it_list=first_it_list.difference(set([patrols[minutes%len(patrols)]]))
stdout.write(str(minutes))
main()
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 18ms | 11708 KiB | ||||
2 | Accepted | 17ms | 11904 KiB | ||||
subtask2 | 30/30 | ||||||
3 | Accepted | 25ms | 13060 KiB | ||||
4 | Accepted | 19ms | 13516 KiB | ||||
5 | Accepted | 28ms | 13356 KiB | ||||
6 | Accepted | 28ms | 13748 KiB | ||||
7 | Accepted | 25ms | 13856 KiB | ||||
8 | Accepted | 19ms | 13956 KiB | ||||
9 | Accepted | 243ms | 14436 KiB | ||||
subtask3 | 0/30 | ||||||
10 | Time limit exceeded | 1.57s | 38468 KiB | ||||
11 | Time limit exceeded | 1.574s | 39416 KiB | ||||
12 | Time limit exceeded | 1.572s | 41400 KiB | ||||
13 | Time limit exceeded | 1.588s | 44080 KiB | ||||
14 | Time limit exceeded | 1.585s | 46072 KiB | ||||
subtask4 | 0/40 | ||||||
15 | Accepted | 939ms | 116292 KiB | ||||
16 | Accepted | 728ms | 120332 KiB | ||||
17 | Time limit exceeded | 1.559s | 49816 KiB | ||||
18 | Time limit exceeded | 1.59s | 50872 KiB | ||||
19 | Time limit exceeded | 1.55s | 49640 KiB | ||||
20 | Time limit exceeded | 1.57s | 50696 KiB | ||||
21 | Time limit exceeded | 1.562s | 50656 KiB | ||||
22 | Time limit exceeded | 1.567s | 52828 KiB | ||||
23 | Accepted | 412ms | 111000 KiB | ||||
24 | Time limit exceeded | 1.577s | 46688 KiB |