Bzoj 2100 Usaco2010 Dec Apple Delivery

Source: Internet
Author: User

2100: [Usaco2010 dec]apple Delivery time limit:10 Sec Memory limit:64 MB
submit:894 solved:348
[Submit] [Status] [Discuss]
Description

Bessie has a crisp red apples to deliver to both of her friends in the herd. Of course, she travels the C (1 <= C <= 200,000) cowpaths which is arranged as the usual graph which connects P (1 <= P <= 100,000) pastures conveniently numbered from 1..p:no Cowpath leads from a pasture to itself, Cowpaths is b Idirectional, each cowpath have a associated distance, and, best of all, it's always possible to get from any pasture to Any other pasture. Each cowpath connects, differing pastures p1_i (1 <= p1_i <= p) and p2_i (1 <= p2_i <= p) with a distance b Etween them of d_i. The sum of the distances d_i does not exceed 2,000,000,000. What's the minimum total distance Bessie must travel to deliver both apples by starting at pasture PB (1 <= PB <= P ) and visiting Pastures PA1 (1 <= PA1 <= p) and PA2 (1 <= PA2 <= p) in any order. All three of these pastures is distinct, of course. Consider this map of bracketed pasture numbers and cowpaths WITh distances:  if Bessie starts at pasture [5] and delivers apples to pastures [1] and [4], she best path is:5 6-> 7, 3, 2, 1* with a total distance of 12.

A P-point of the graph, C is the right way.
CLJ to from the PB Point (Home), both to Pa1 Point Noi to win gold medal, also to Pa2 Point CMOS stadium to take gold medal. (Don't go home on the way)
You can go to NOI first, or you can go to the CMO first.
Of course God Ben Clj is sure to make the total distance minimum, output minimum value. Input

* Line 1:line 1 contains five space-separated integers:c, P, PB, PA1, and PA2 * Lines 2..c+1:line i+1 describes Cowpath I by naming II pastures it connects and the distance between Them:p1_i, P2_i, d_i

Output

* Line 1:the Shortest distance Bessie must travel to deliver both apples

Sample Input9 7 5) 1 4
5 1 7
6 7 2
4 7 2
5 6 1
5 2 4
4 3 2
1 2 3
3 2 2
2 6 3



Sample Output12
HINT

to seek translation ... In the station PM me ....

Source

Silver

Because the graph is an SPFA diagram, so do two times, respectively, PA1 and PA2 as the starting point can be

1#include <bits/stdc++.h>2 #definell Long Long3 #defineINF 10000004 #defineEPS 1e-75 using namespacestd;6InlineintRead () {7     intx=0;intf=1;CharCh=GetChar ();8      while(!isdigit (CH)) {if(ch=='-') f=-1; ch=GetChar ();}9      while(IsDigit (CH)) {x=x*Ten+ch-'0'; ch=GetChar ();}Ten     returnx*F; One } A Const intmaxn=1e6+Ten; - structnode{ -     inty,next,v; the }E[MAXN]; - intLINKK[MAXN],LEN,N,M,DIS[MAXN],VIS[MAXN]; -InlinevoidInsertintXxintYyintVV) { -e[++len].y=yy;e[len].next=linkk[xx];e[len].v=vv;linkk[xx]=Len; + } - voidSPFA (intSt) { +Deque <int>Q; Amemset (DIS,Ten,sizeof(DIS)); atmemset (Vis,0,sizeof(Vis)); -Q.push_back (ST);d is[st]=0; vis[st]=1; -      while(!Q.empty ()) { -         intTn=q.front (); Q.pop_front (); vis[tn]=0; -          for(intI=linkk[tn];i;i=E[i].next) { -             if(dis[e[i].y]>dis[tn]+e[i].v) { indis[e[i].y]=dis[tn]+e[i].v; -                 if(!Vis[e[i].y]) { tovis[e[i].y]=1; +                     if(!q.empty () &&dis[q.front ()]>Dis[e[i].y]) Q.push_front (E[I].Y); -                     ElseQ.push_back (E[I].Y); the                 } *             } $         }Panax Notoginseng     } - } the intMain () { +M=read (); N=read ();intS=read ();intT1=read ();intT2=read (); A      for(intI=1; i<=m;i++){ the         intXx=read ();intYy=read ();intvv=read ();; + Insert (XX,YY,VV); insert (YY,XX,VV); -     } $ SPFA (t1); $     intans=dis[t2]+Dis[s]; - SPFA (T2); -Ans=min (ans,dis[t1]+Dis[s]); thecout<<ans<<Endl; -     return 0;Wuyi}
View Code

Bzoj 2100 Usaco2010 Dec Apple Delivery

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.