TYVJ 1031 heat Wave shortest circuit

Source: Internet
Author: User

Heat

Time limit:1 Sec Memory limit:256 MB

Topic Connection

http://tyvj.cn/p/1031

DescriptionTexas's simple people 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.). Consider this map with 7 towns. Town 5 is a source of milk, and town 4 is the end point (the number in parentheses is the passage cost of the road).

[1]----1---[3]-
/               \
[3]---6---[4]---3--[3]--4
/               /       /|
5--[3]----[2]-|
\       /        /       |
[5]---7---[2]--2---[3]---
| /
[1]------

After Route 5-6-3-4 Total cost of 3 (5-&GT;6) + 4 (6->3) + 3 (3->4) = 10 is required.

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 &lt;= 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.input* 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 a space: Rs, RE and CI
Output * First line: A single integer representing the shortest-circuiting length of TS to TE. (not cost?) How did you suddenly become blunt?
--the translator's note) data guarantees that there is at least one road. Sample Input7 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 1Sample Output7
HINT

Test instructions

Exercises

An ordinary shortest-path algorithm, ah, with the idea of similar bfs to think about the shortest circuit ~

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 200001#defineMoD 10007#defineEPS 1e-9//const int INF=0X7FFFFFFF; //infinitely LargeConst intinf=0x3f3f3f3f;/*inline ll read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;}  int buf[10];inline void Write (int i) {int p = 0;if (i = = 0) p++;  else while (i) {buf[p++] = i% 10;i/= 10;}  for (int j = p-1; J >=0; j--) Putchar (' 0 ' + buf[j]); printf ("\ n");}*///**************************************************************************************inline ll read () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}structnode{intx, y;}; Vector<node>EDGE[MAXN];voidAdd_edge (intXintYintz)    {Edge[x].push_back ({y,z}); Edge[y].push_back ({x,z});}intMain () {intn,m,s,t; CIN>>n>>m>>s>>T;  for(intI=0; i<m;i++)    {        intA,b,c; CIN>>a>>b>>C;    Add_edge (A,B,C); }    intD[MAXN];  for(intI=0; i<=n;i++) D[i]=inf; Queue<int>Q;    Q.push (s); D[s]=0;  while(!Q.empty ()) {        intnow=Q.front ();        Q.pop ();  for(intI=0; I<edge[now].size (); i++) {node U=Edge[now][i]; if(d[now]+u.y<d[u.x]) {d[u.x]=d[now]+u.y;            Q.push (u.x); } }} cout<<d[t]<<Endl;}

TYVJ 1031 heat Wave shortest circuit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.