28332023-01-29 00:55:45VMGoJoRendőrségi őrjárat 2python3Runtime error 0/1001.578s119504 KiB
from sys import stdin, stdout

minutes:int
first_it_list:set()
second_it_list:set()
found:bool
patrols:list()
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)

    global minutes,first_it_list,second_it_list,found,patrols
    #print(nodes)
    patrols=stdin.readline().split()
    patrols = [int(i) for i in patrols]
    
    minutes=0
    first_it_list=[0]
    found=False
    #BREADTH FIRST SEARCH
    def do_layer(first_it_l):
        rt_set=set([])
        for i in first_it_l:
            for j in nodes[i]:
                rt_set.add(j)
        return rt_set

    def check_stuff(set_in):
        global found,patrols,minutes
        #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
1Accepted18ms11880 KiB
2Accepted17ms12052 KiB
subtask20/30
3Accepted25ms13060 KiB
4Accepted20ms13276 KiB
5Accepted28ms13380 KiB
6Accepted28ms13408 KiB
7Accepted25ms13224 KiB
8Accepted20ms13328 KiB
9Runtime error230ms15204 KiB
subtask30/30
10Runtime error677ms80072 KiB
11Runtime error680ms81188 KiB
12Runtime error691ms85788 KiB
13Runtime error606ms89592 KiB
14Runtime error703ms93372 KiB
subtask40/40
15Accepted1.231s115560 KiB
16Accepted970ms119504 KiB
17Time limit exceeded1.578s49168 KiB
18Time limit exceeded1.578s51620 KiB
19Time limit exceeded1.578s51572 KiB
20Time limit exceeded1.575s51912 KiB
21Time limit exceeded1.565s51892 KiB
22Time limit exceeded1.565s51928 KiB
23Accepted456ms111056 KiB
24Runtime error702ms93920 KiB