28312023-01-29 00:45:09VMGoJoRendőrségi őrjárat 2python3Runtime error 0/1001.582s119680 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
1Accepted18ms11464 KiB
2Accepted17ms11864 KiB
subtask20/30
3Accepted25ms13188 KiB
4Accepted19ms13152 KiB
5Accepted27ms13688 KiB
6Accepted28ms13596 KiB
7Accepted25ms13804 KiB
8Accepted19ms13464 KiB
9Runtime error236ms15672 KiB
subtask30/30
10Runtime error684ms79836 KiB
11Runtime error681ms81592 KiB
12Runtime error597ms85900 KiB
13Runtime error700ms89984 KiB
14Runtime error722ms93332 KiB
subtask40/40
15Accepted1.245s115344 KiB
16Accepted976ms119680 KiB
17Time limit exceeded1.542s49040 KiB
18Time limit exceeded1.582s49232 KiB
19Time limit exceeded1.57s51396 KiB
20Time limit exceeded1.554s50592 KiB
21Time limit exceeded1.574s51664 KiB
22Time limit exceeded1.575s51768 KiB
23Accepted458ms110932 KiB
24Runtime error708ms93828 KiB