


Cost of entries where j < i will be represented as INT_MAX VALUE which is 10000 in the price matrix.
If ‘N’ = 3
'PRICE[3][3]' = {{0, 15, 80,},
{INF, 0, 40},
{INF, INF, 0}};
First, go from 1st station to 2nd at 15 costs, then go from 2nd to 3rd at 40. 15 + 40 = 55 is the total cost.It is cheaper than going directly from station 1 to station 3 as it would have cost 80.
The output will be 55.
The first line of input contains an integer 'T' denoting the number of test cases.
The first line of each test case contains a single integer 'N', Where ‘N’ is the number of rows and columns in the ‘PRICE’ matrix.
The next ‘N’ lines is as follows: Each line contains ‘N’ space-separated integers representing the cost of pairs (i,j) where ‘i’ and ‘j’ are indices of the matrix ‘PRICE’.
For each test case, return the minimum price that will have to be paid such that the train reaches from 1st to 'N'th station.
Print the output for each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 1000
Time Limit: 1 sec
The idea is to calculate the minimum price between all pair of stations using Floyd Warshall Algorithm:
The idea is based on the fact that the given input matrix is a Directed Acyclic Graph (DAG) because we can go from a smaller station to another and not the other way around hence DAG. The shortest path in DAG can be calculated using topological sorting.