This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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))
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |