Topic Source codevs1077
Title Description
Description
Known n points (n<=100), give you a n*n square, a[i,j] represents the direct distance from the point I to the J point.
There are now Q queries, each asking two positive integers, a and B, allowing you to find the shortest distance between A and B.
Meet A[i,j]=a[j,i];
Enter a description input
Description
The first line is a positive integer n, followed by n rows of n positive integers per row, satisfies a[i,i]=0, and then lines a Q, followed by Q line, two positive integers a and b per line.
outputs description output
Description
A total of Q lines, one integer per line.
sample input to
sample
3
0 1 1
1 0 3
1 3 0
1
2 3
Sample output Sample
outputs
2
data
size & Hint
N<=100,q may be very large. G[I][J] All >=0
Please use the FLYOD algorithm
Please note that with C + +: Because of the large input data, using CIN and cout causes the program to time out. Please use scanf and printf for input and output.
A topic like this is a bare Floyd, so call him up as a template.
Floyd is actually the idea of dynamic planning, each cycle is equivalent to the selection of the first k points of the shortest.
Directly on the code:
--the teacher, so preach bred doubts also.
"Daily Learning" "Floyd" codevs1077 multi-source Shortest path