Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=2100
Solution:
Typical of the shortest, from two points to run the template is good, but a bit of trouble is, if run Dijkstra, to use heap to optimize, if run SPFA to use SLF (of course used lll also line) to optimize, in short, can not bare template to run.
Program:
#include <iostream>#include<cstdio>#include<cstring>#include<queue>#defineINF 2100000000using namespacestd;structding{intTo,w,next;} edge[400010];structding2{intP,di; BOOL operator< (ConstDing2&a)Const { returna.di<di; }};intcnt,ans,n,m;inthead[100010],dis[100010];p riority_queue<ding2>Q;voidAddintUintVintd) {edge[++cnt].to=v; edge[cnt].w=d; edge[cnt].next=head[u];head[u]=CNT;}voidDijkstraintSt) { for(intI=1; i<=n;i++) dis[i]=INF; Q.push ((ding2) {St,0}); DIS[ST]=0; while(!Q.empty ()) {Ding2 now=q.top (); Q.pop (); if(NOW.DI!=DIS[NOW.P])Continue; for(intI=head[now.p];i;i=Edge[i].next) { intk=edge[i].to; if(dis[k]>now.di+EDGE[I].W) {Dis[k]=now.di+EDGE[I].W; Q.push ((ding2) {k,dis[k]}); } } }}intMain () {intSt,en1,en2; scanf ("%d%d%d%d%d",&m,&n,&st,&en1,&en2); intx,y,d; for(intI=1; i<=m;i++) {scanf ("%d%d%d",&x,&y,&d); Add (x,y,d); Add (y,x,d); } Dijkstra (EN1); Ans+=dis[en2]+Dis[st]; Dijkstra (EN2); Ans=min (ans,dis[en1]+dis[st]); printf ("%d\n", ans); return 0;}
Bzoj 2100: [Usaco2010 dec]apple Delivery