k,n,m,o=map(int,input().split())
caminos=[]
for i in range(n):
caminos.append([])
for i in range(m):
a,b,t=map(int,input().split())
caminos[b].append([a,t])
def llegar(b,t,camino,caminos,a,opciones):
if(len(camino)!=0):
for i in camino:
if(i[0]==a):
opciones.append(t+i[1])
opciones=llegar(i[0],t+i[1],caminos[i[0]],caminos,a,opciones)
return opciones
for i in range(o):
t=0
a,b=map(int,input().split())
opciones=[]
opciones=llegar(b,t,caminos[b],caminos,a,opciones)
if(len(opciones)==0):
print('-1')
else:
print(min(opciones))
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
144 ms |
17124 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
256 ms |
24328 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2908 KB |
Output is correct |
2 |
Correct |
10 ms |
2864 KB |
Output is correct |
3 |
Correct |
10 ms |
2908 KB |
Output is correct |
4 |
Correct |
11 ms |
2908 KB |
Output is correct |
5 |
Correct |
11 ms |
2908 KB |
Output is correct |
6 |
Correct |
14 ms |
3212 KB |
Output is correct |
7 |
Execution timed out |
3057 ms |
3676 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2908 KB |
Output is correct |
2 |
Correct |
10 ms |
2864 KB |
Output is correct |
3 |
Correct |
10 ms |
2908 KB |
Output is correct |
4 |
Correct |
11 ms |
2908 KB |
Output is correct |
5 |
Correct |
11 ms |
2908 KB |
Output is correct |
6 |
Correct |
14 ms |
3212 KB |
Output is correct |
7 |
Execution timed out |
3057 ms |
3676 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
144 ms |
17124 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |