Pondo Path Queries
View as PDFPondo Path Queries
Problem Statement
You are given a directed graph with  vertices and 
 edges with weights.
You are also given 
 queries each containing three integers 
, 
 and 
. For each query determine the shortest walk from 
 to 
 using at most 
 edges.
NOTE: A walk is like a path but can repeat vertices.
Input Format
Your first line will contain three space-separated integers , 
 and 
.
Your next 
 lines will contain three integers each 
, 
 and 
 representing and edge from 
 to 
 with weight 
.
Your next 
 lines will contain three integers each 
, 
 and 
 representing the start point, end point and max number of edges respectively.
Output Format
You should output one line for each query, representing the minimum distance from  to 
 after a walk of at most 
 in length.
If it is not possible to reach in 
 edges or less, then output 
NOT POSSIBLE.
Constraints
YOU CAN HAVE EDGES BETWEEN THE SAME NODES
Sample Cases
Input 1
5 4 10
1 2 1
2 3 2 
3 4 -2 
4 5 3
1 2 0
1 2 10
1 3 1
1 3 2
1 5 4
5 5 4
5 4 4
5 3 4
5 2 4
5 1 4
Output 1
NOT POSSIBLE
1
NOT POSSIBLE
3
4
0
NOT POSSIBLE
NOT POSSIBLE
NOT POSSIBLE
NOT POSSIBLE
Input 2
2 2 10
1 2 1
2 1 -2
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 1 6
1 1 7
1 1 8
1 1 9
1 1 10
Output 2
0
-1
-1
-2
-2
-3
-3
-4
-4
-5
Template
n, m, q = map(int, input().split())
edges = [None] * m
for i in range(m):
    u, v, w = map(int, input().spilt())
    edges[i] = (u, v, w)
# print your output
Comments