Description
John Home has n pieces of grass, numbered 1 to N, between each other by M two-way road connection, the road link between the Ai and Bi, the two grasslands may have many roads, but no road will be connected to the same grassland, the existing road can be guaranteed that any two grass is connected.
One day, John announced that the cows would walk to collect tolls, as long as the cows walk on the road I, will charge Li yuan. In addition, John asked each cow to buy a license plate, he set a licence standard for each lawn, if the cow bought a license plate price is lower than the standard of a grass, she will be banned into the grass. The standard of the license plate for the grass of the first piece is Ci.
A new policy, cows dare not say, there is a Q cow to you the most economical way to walk, the first cow from the grass si to Ti. Please help them calculate, choose what route to save money?
Input Format
First line: three integers N, M and q,1≤n≤250; 1≤m≤10000; 1≤q≤10000
? The second line to the Nth + 1 line: line i + 1 has an integer ci,1≤ci≤10^6
? Nth + 2 lines to nth + M + 1 lines: The line i + 1 has three integers ai,bi and li,1≤ai; B I≤n, 1≤li≤10^6
? Nth + M + 2 lines to nth + M + Q + 1 lines: i + N + M + 1 lines have two integers Si and ti,1≤si,ti≤n
Output Format
First line to line Q: line I has an integer representing the minimum cost from Si to Ti
Sample Input
Sample Input 5 7 2253341 2 31 3 22 5 35 3 15 4 12 4 33 4 41 42 3
Sample Output
Sample output 89 The best way to explain is 1→3→5→4 and 2→5→3, respectively.
A good topic of floyed diagram, to thoroughly understand floyed to play the positive solution;
First of all, the most violent play is to enumerate licences, then the time complexity will reach n^4;40%;
n<=250; in the data so we obviously have to consider optimization; n^3?;
It is impossible to omit the starting point and the ending point and the transition point in the floyed;
The direction is clear; The enumeration of the signs to O (1);
Let's think about the nature of these paths
You may wish to set S as the starting point; t is the end point;
1: The higher the cost of road signs the s->t is a non-ascending sequence;
2: The maximum road signs on the cost + distance = Total cost;
Then we sort the points of each point, then floyed;100% from small to large enumeration transition points;
The rationality of sorting is that the path satisfies the nature of 1; So the shortest circuit will be updated continuously during the floyed process;
The end of the s->t is not changed; the point of the transition point continues to increase so the maximum point of the path will continue to update;
Then it is reasonable to consider all the circumstances;
Core Program
BOOLcmpConstSt X,ConstSt Y) { if(X.W<Y.W)return true; return false;} Std::sort (Mu+1, mu+1+n,cmp); for(i=1; i<=n;++i) {G[i][i]=W[i]; F[i][i]=0; } for(intz=1; z<=n;++z) {k=mu[z].id; for(i=1; i<=n;++i) for(j=1; j<=n;++j) {F[i][j]=min (f[i][k]+F[k][j],f[i][j]); G[j][i]=g[i][j]=min (G[i][j],max (W[k],max (w[i],w[j)) +F[i][j]); } }
Usaco tolls Cow Toll Paths, DEC