28322023-01-29 00:47:21VMGoJoRendőrségi őrjárat 2python3Runtime error 0/1001.582s119624 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()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted18ms11804 KiB
2Accepted17ms12080 KiB
subtask20/30
3Accepted26ms13076 KiB
4Accepted20ms13284 KiB
5Accepted27ms13428 KiB
6Accepted28ms13108 KiB
7Accepted26ms13452 KiB
8Accepted20ms13872 KiB
9Runtime error238ms15352 KiB
subtask30/30
10Runtime error587ms79872 KiB
11Runtime error683ms81248 KiB
12Runtime error694ms85996 KiB
13Runtime error605ms90096 KiB
14Runtime error704ms93308 KiB
subtask40/40
15Accepted990ms115624 KiB
16Accepted1.118s119624 KiB
17Time limit exceeded1.549s49144 KiB
18Time limit exceeded1.582s50320 KiB
19Time limit exceeded1.57s51436 KiB
20Time limit exceeded1.567s50668 KiB
21Time limit exceeded1.582s51844 KiB
22Time limit exceeded1.574s51876 KiB
23Accepted545ms110828 KiB
24Runtime error707ms94200 KiB