77292024-01-10 18:48:35SatyaTom és Jerry 1 (80)python3Time limit exceeded 20/80600ms66984 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'
            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'
            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/018ms11636 KiB
2Time limit exceeded0/0524ms5276 KiB
3Accepted4/418ms12304 KiB
4Accepted4/418ms12364 KiB
5Accepted4/424ms12872 KiB
6Accepted4/426ms13056 KiB
7Accepted4/496ms13800 KiB
8Time limit exceeded0/4510ms14988 KiB
9Time limit exceeded0/4536ms15572 KiB
10Time limit exceeded0/4600ms6992 KiB
11Runtime error0/457ms21980 KiB
12Runtime error0/468ms24340 KiB
13Runtime error0/4101ms29464 KiB
14Runtime error0/4248ms43568 KiB
15Runtime error0/4375ms55556 KiB
16Runtime error0/4375ms58948 KiB
17Runtime error0/4326ms66776 KiB
18Runtime error0/4328ms54464 KiB
19Runtime error0/4328ms54208 KiB
20Runtime error0/4333ms53988 KiB
21Runtime error0/4303ms51936 KiB
22Runtime error0/4323ms66984 KiB