Pondo Path Queries


Pondo Path Queries

Problem Statement

You are given a directed graph with nn vertices and mm edges with weights. You are also given QQ queries each containing three integers uu, vv and kk. For each query determine the shortest walk from uu to vv using at most kk edges. NOTE: A walk is like a path but can repeat vertices.

Input Format

Your first line will contain three space-separated integers nn, mm and QQ. Your next mm lines will contain three integers each uu, vv and ww representing and edge from uu to vv with weight ww. Your next QQ lines will contain three integers each uu, vv and kk 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 uu to vv after a walk of at most kk in length. If it is not possible to reach in kk edges or less, then output NOT POSSIBLE.

Constraints

  • 1n,u,v1001 \leq n, u, v \leq 100
  • 1mn(n1)1 \leq m \leq n \cdot (n - 1)
  • 100w100-100 \leq w \leq 100
  • 1k1091 \leq k \leq 10^9

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

Code 1
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

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.