Home > Back-end >  Codevs 1557
Codevs 1557

Time:09-28

don't know why, this code won't always right, who is a great god help look at it?
P1557 heat (SPFA)
Topic describes the Description

Texas a simple people are suffering from huge heat this summer!!!!!! Their Texas longhorn tastes good, but they are not very good at producing dairy products are rich in cream, Farmer John to the world at this time of sorrow, sorrow, and the spirit of the world of joy but joy, after first to undertake a large number of shipments to Texas nutrition milk, cold to relieve the pain of the texans stand the heat,
FJ has studied the milk from Wisconsin to Texas route, the route including starting point and end point have been first T (1 & lt;=T & lt;=2500) town, easily labeled from 1 to T, in addition to the starting point and end point from each town by two two-way road is connected to at least two other towns, each road has a through fees (including gas, tolls, etc.),
Given a map, contains the C (1 & lt;=C & lt;=6200) of directly linking the two towns, the starting point of each road by road Rs, end Re (1 & lt;=Rs & lt;=T; 1 & lt;=Re & lt;=T), and cost (1 & lt;=Ci & lt;=1000), from the starting town Ts (1 & lt;=Ts & lt;=T) to the town at the end of Te (1 & lt;=Te & lt;=T) the minimum total cost,
enter Description Input Description
The first line: 4 integers separated by Spaces: T, C, Ts, Te
Line 2 to the first C + 1: the I + 1 line describes the way, I have three integers separated by Spaces: Rs, Re and Ci
Output describing the Output Description
A single integer from Ts to Te, the minimum total cost, data to ensure there are at least a road,
Sample Input Sample Input
7 11 5 4
4 2
1 4 3
7 2 2
3, 4, 3
5 7
7 3 3
6 1 1
6, 3, 4,
2 4 3
5 6 3
7 2 1
Sample Output Sample Output
7

Code:
 var 
A: array [1.. 2500, 1.. 2500] of longint;
F: an array of Boolean [1.. 6200];
D: array [1.. 6200] of longint;
I, j, k, m, n, x, y, z, mn, b, m: longint;
The begin
Fillchar (f, sizeof (f), true);
Fillchar (d, sizeof (d), 100);
Fillchar (a, sizeof (a), 100);
Readln (n, m, k, b);
For I:=1 to m do
The begin
Readln (x, y, z);
A (x, y) :=z;
A (y, x) :=z;
end;
D: [k]=0;
F: [k]=false;
For I=1 to n - 1 do
The begin
For j:=1 to n do
If [j] (f) and (d) [j] & gt; A [k, j] + d [k]) then
The begin
D [j] :=a [k, j] + d [k].
end;
Mn:=10000;
For j:=1 to n do
If (mn> D [j]) and (f) [j] then mn:=d [j];
For j:=1 to n do
If [j]=mn (d) and (f) [j] then
The begin
F: [j]=false;
K:=j;
break;
end;
end;
Writeln (d [k]);
End.
  • Related