77312024-01-10 18:54:29SatyaTom és Jerry 1 (80)python3Time limit exceeded 20/80600ms67124 KiB
beolvas = input()
beolvas = beolvas.strip().split(' ')
n = int(beolvas[0])
m = int(beolvas[1])
t = int(beolvas[2])
p = int(beolvas[3])
e = int(beolvas[4])
graf = []
kezd = []

for i in range(n+1):
    graf.append([])

for i in range(m):
    beolvas = input()
    beolvas = beolvas.strip().split(' ')
    lista = [beolvas[1], beolvas[2]]
    graf[int(beolvas[0])].append(lista)
    lista2 = [beolvas[0], beolvas[2]]
    graf[int(beolvas[1])].append(lista2)


for i in range(p):
    k = int(input())
    kezd.append(k)

tom_tav = [-1]*(n+1)
tom_tav[6] = 0

def tomBejar(t, depth):
    global tom_tav
    for i in range(len(graf[t])):
        if int(graf[t][i][1]) == 2:
            if tom_tav[int(graf[t][i][0])] == -1 or tom_tav[int(graf[t][i][0])] > depth:
                tom_tav[int(graf[t][i][0])] = depth
                tomBejar(int(graf[t][i][0]), depth+1)

tomBejar(t, 1)

jerry_nyer = ['NEM']*p
jerry_tav = [-1]*(n+1)

def jerryBejar(index, j, depth):
    global jerry_nyer
    for i in range(len(graf[j])):
        if tom_tav[int(graf[j][i][0])] == -1:
            if int(graf[j][i][0]) == e:
                jerry_nyer[index] = 'IGEN'
                return
            elif jerry_tav[int(graf[j][i][0])] == -1:
                jerry_tav[int(graf[j][i][0])] = depth+1
                jerryBejar(index, int(graf[j][i][0]), depth+1)
            elif jerry_tav[int(graf[j][i][0])] > depth+1:
                jerry_tav[int(graf[j][i][0])] = depth+1
                jerryBejar(index, int(graf[j][i][0]), depth+1)
        elif depth+1 < tom_tav[int(graf[j][i][0])]:
            if int(graf[j][i][0]) == e:
                jerry_nyer[index] = 'IGEN'
                return
            else:
                if jerry_tav[int(graf[j][i][0])] == -1:
                    jerry_tav[int(graf[j][i][0])] = depth + 1
                    jerryBejar(index, int(graf[j][i][0]), depth + 1)
                elif jerry_tav[int(graf[j][i][0])] > depth+1:
                    jerry_tav[int(graf[j][i][0])] = depth + 1
                    jerryBejar(index, int(graf[j][i][0]), depth + 1)

for i in range(p):
    jerry_tav = [-1] * (n + 1)
    jerry_tav[kezd[i]] = 0
    jerryBejar(i, kezd[i], 0)

for i in jerry_nyer:
    print(i)
SubtaskSumTestVerdictTimeMemory
base20/80
1Accepted0/019ms11940 KiB
2Time limit exceeded0/0600ms5204 KiB
3Accepted4/417ms12584 KiB
4Accepted4/418ms12620 KiB
5Accepted4/424ms12612 KiB
6Accepted4/426ms12940 KiB
7Accepted4/494ms13484 KiB
8Time limit exceeded0/4510ms14748 KiB
9Time limit exceeded0/4523ms15456 KiB
10Time limit exceeded0/4564ms6772 KiB
11Runtime error0/459ms21860 KiB
12Runtime error0/471ms24452 KiB
13Runtime error0/497ms29396 KiB
14Runtime error0/4230ms43504 KiB
15Runtime error0/4360ms55676 KiB
16Runtime error0/4363ms58780 KiB
17Runtime error0/4326ms67124 KiB
18Runtime error0/4335ms54968 KiB
19Runtime error0/4331ms54036 KiB
20Runtime error0/4279ms54516 KiB
21Runtime error0/4312ms52252 KiB
22Runtime error0/4321ms66836 KiB