[Daily learning] [floyd] codevs1077 multi-source shortest answer, floydcodevs1077
Source: codevs1077
Description
Description
N points (n <= 100) are known, and the square matrix of n x n is given. a [I, j] indicates the direct distance from vertex I to vertex j.
Now we have Q queries. Each query has two positive integers, a and B. This allows you to find the shortest distance between a and B.
Meet a [I, j] = a [j, I];
Input description
Input Description
The first line is a positive integer n, And the next n rows have n positive integers in each line, satisfying the conditions of a [I, I] = 0, and then a row of Q, followed by a row of Q, each row has two integers, a and B.
Output description
Output Description
A total of Q rows. Each row has an integer.
Sample Input
Sample Input
3
0 1 1
1 0 3
1 3 0
1
2 3
Sample output
Sample Output
2
Data range and prompt
Data Size & Hint
N <= 100, Q may be very large. G [I] [j] All> = 0
Use the flyod Algorithm
If you use C/C ++, note that due to the large input data, using cin and cout may cause program timeout. Use scanf and printf for input and output.
Such a question is a raw floyd, so it is used as a template.
Floyd is actually the idea of dynamic planning. Each cycle is equivalent to finding the Shortest Path of the first k points.
Directly run the Code:
-The teacher, so the Evangelist is also confused.