Time limit: 10000ms single point time limit: 1000ms memory limit: 256MB description
The noon of Halloween, Little Hi and Little ho after lunch, came to a new haunted house!
There are a total of n locations in the Haunted house, numbered 1, respectively. N, there are some road connections between these n locations, there may be multiple roads connected between the two locations, but there is no road where both ends are the same location.
Because there is no stomach pressure, small hi and small ho decided to stroll around this haunted house, stroll, small hi produced this question: haunted house in any two locations between the shortest path is how much?
Hint: In fact, if you are happy, you can start using Dijstra algorithm _ (: З"∠) _ from each node. Input
Each test point (input file) has and has only one set of test data.
In a set of test data:
The 1th Act is 2 integers n, M, respectively, indicating the number of places in the haunted house and the number of roads.
The next M-line, each line describes a road: where the I behavior of three integers u_i, v_i, Length_i, indicates that there is a road length v_i between the place numbered U_i and the place numbered length_i.
For 100% of data, meet N<=10^2,m<=10^3, 1 <= length_i <= 10^3.
For 100% of the data, meet any of the two locations in the maze can reach each other.
Output
For each set of test data, output a n*n matrix A, in which row I, Column J, indicates the length of the shortest path from the first place to the J location, when the i=j should be 0.
-
-
Sample input
-
-
5 121 2 9672 3 9003 4 7714 5 1962 4 7883 1 6371 4 8832 4 825 2 6471 4 1982 4 1815 2 665
-
-
Sample output
-
The simplest Freud algorithm, multi-source shortest path.
1#include"iostream"2#include"Cstdio"3 using namespacestd;4 #defineMAX 66665 intn,m;6 intmap[1111][1111];7 8 voidFloyd ()9 {Ten inti,j,k; One for(k =1; k <= N; ++k) A for(i =1; I <= N; ++i) - for(j =1; J <= N; ++j) - if(Map[i][k] + map[k][j] <Map[i][j]) theMAP[I][J] = Map[i][k] +Map[k][j]; - } - voidShow () - { + inti,j; - for(i =1; I <= N; + +i) { + for(j =1; J <= N; ++j) Aprintf"%d", Map[i][j]); atPuts""); - } - } - - intMain () - { in intI, J, A, B, W; -CIN >> N >>m; to for(i =1; I <= N; ++i) + for(j =1; J <= N; ++j) { -MAP[I][J] =MAX; the if(i = = j) Map[i][j] = map[j][i] =0; * } $ for(i =0; i < m; + +i) {Panax Notoginsengscanf"%d%d%d",&a,&b,&W); - if(W <Map[a][b]) theMAP[A][B] = Map[b][a] =W; + } A Floyd (); the Show (); + return 0; -} code June
Hihocoder 24th Week (Floyd)