Posted: 6 Jul, 2021
There are ‘N’ cities numbered from 0 to ‘N’ - 1 and ‘M’ river connecting two cities in a Starlink Kingdom. The only way to travel from one city to another is by swimming through a river. Ninja is on a vacational journey and wants to do ‘Q’ travel. The energy required to swim against the river is ‘w’ and with the flow of river is zero, it means if the flow of river is from city ‘u’ to ‘v’ then the energy required to swim from ‘v’ to ‘u’ is ‘w’. Ninja has special power to reverse the direction of flow of water in the river. Ninja wants to minimize his energy consumption for this journey. Help Ninja to find the minimum energy required to complete his journey using his special power. He can reverse the direction of flow of any river any number of times before starting his journey( he may not use his power ).
Note : Energy consumption of one journey is equal to the sum of energy of each trip. There can be more than one river between any two cities.
The first line contains one positive integer ‘T’, denoting the number of test cases, then ‘T’ test cases follows The first line of each test case contains three integers ‘N’ ‘M’ and ‘Q’, denoting the number of cities, the number of rivers and number of travel. The next ‘M’ lines of each test case contains three space-separated integers ’u’ , ‘v’ and ‘w’, denoting connection between cities ‘u’ and ‘v’ where river flow from ‘u’ to ‘v’ and energy required against flow is ‘w’. The next ‘Q’ lines of each test case contain two integers ‘x’ and ‘y’, denoting each travel from ‘x’ to ‘y’.
The first and the only line of each test case contains one integer ‘X’, denoting the minimum energy required to complete his journey using his special power ( he may not use his special power). Output of each test case will be printed on a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5 1 <= N, M, Q <= 1000 0 <= u, v <= N - 1, u != v 0 <= ‘x’, ‘y’ <= N - 1 Time Limit: 1 sec.