Bzoj 2100: [Usaco2010 dec]apple Delivery

Source: Internet
Author: User

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

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.