1557 heat Wave
Time limit: 1 s space limit: 256000 KB title level: Diamonds Diamond Title Description Description
The simple people of Texas are suffering a huge heat wave this summer ... Their Texas horned cows are good to eat, but they are not very good at producing cream-rich dairy products. Farmer John at this time first, enjoy spirit, Shenxianshizu to Texas to carry a large number of nutritious cold milk, to alleviate the Texan people endure the pain of heat.
FJ has studied the route of transporting milk from Wisconsin to Texas. These routes include a starting point and an end point that are preceded by a total of T (1 <= t <= 2,500) towns, conveniently labeled 1 to T. In addition to the beginning and end of the field each town is connected by two bidirectional roads to at least two other towns. Each road has a pass fee (including fuel, toll, etc.).
Given a map, the roads containing C (1 <= C <= 6,200) are directly connected to 2 towns. Each road consists of the beginning of the road RS, the end point re (1 <= Rs <= t; 1 <= Re <= t), and the cost (1 <= Ci <= 1,000). The minimum total cost for the town Te (1 <= te <= t) from the beginning of the town TS (1 <= TS <= t) to the end point. Enter a description input Description
First line: 4 integers separated by a space: T, C, Ts, Te
2nd to C+1: line i+1 describes article I road. There are 3 integers separated by spaces: Rs, RE and CI outputs describe output Description
A single integer represents the minimum total cost from TS to TE. The data guarantees that there is at least one road. Sample input to sample
7 11 5 4
2 4 2
1 4 3
7 2 2
3 4 3
5 7 5
7 3 3
6 1 1
6 3 4
2 4 3
5 6 3
7 2 1 Sample outputs sample output
7 data range and hints, size & Hint
5->6->1->4 (3 + 1 + 3)
SPFA of the side table STL:
1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <queue> 5 using Namespa
CE std;
6 int dis[100010],u[100010],v[100100],head[100010],next[100010],exist[100010];
7 int n,m,s,t,x,y,z,tot=0;
8 queue<int> Q;
9 void Bianbao (int x,int y,int z) {ten u[++tot]=y; v[tot]=z; next[tot]=head[x]; head[x]=tot; 14} void Spfa () {memset (dis,127,sizeof (dis)); dis[s]=0; Q.push (S); exist[s]=1; while (!q.
Empty ()) {P=q.front int (); Q.pop (); exist[p]=0; (int i=head[p];i;i=next[i]) if (Dis[u[i]]>dis[p]+v[i]) {dis[u[i]]=dis[p]+v[i]; if (!exist[u[i]) ) {exist[u[i]]=1; Q.push (U[i]); 30} 31} 32
} printf ("%d\n", dis[t]); ("%d%d%d%d", &n,&m,&s,&t), "scanf" (int i=1;i<=m;i++) {scanf ("%d%d%d", &x,&y,&z), Bianbao (x, y, z); Bianbao (y,x,z); 41} 42
SPFA ();
return 0; 44}
Just started STL forgot pop, the result is full time out ~ ~ ~