UVa 12661 Funny Car Racing "Dijkstra"

Source: Internet
Author: User

Test instructions: Given n points, M-Path, each road is represented by 5 integers u,v,a,b,t

U represents the beginning of the road, V is the end point, A is the open time, B is the closing time, T indicates the time required to pass the road

Look at the purple book, because the right side is no longer just the time on the road, but also need to deal with whether to wait

If you don't have to wait, the weight on this path is T.

If you need to wait, the weight of this road is t+wait.

You can use Dijkstra again.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A  - #defineforeach (I,c) for (__typeof (C.begin ()) i = C.begin (); I! = C.end (); ++i) -  thetypedefLong LongLL; - Const intINF = (1<< -)-1; - Const intMod=1000000007; - Const intmaxn=100005; +  - intD[MAXN],USED[MAXN],NEXT[MAXN],FIRST[MAXN]; + intn,m,ecnt,s,t; A  at structedge{ -     intv,a,b,t; - } E[MAXN]; -  - voidAddedge (intUintVintAintBintt) { -next[++ecnt]=First[u]; ine[ecnt].v=v; -E[ecnt].a=A; toe[ecnt].b=b; +e[ecnt].t=T; -first[u]=ecnt; the } *  $ voidDijkstraints) {Panax Notoginseng      for(intI=1; i<=n;i++) d[i]=INF; -d[s]=0; thememset (Used,0,sizeof(used)); +      A      for(intk=1; k<=n;k++){ the         intu,m=INF; +          for(intI=1; i<=n;i++)if(!used[i]&&d[i]<m) m=d[u=i]; -used[u]=1; $          for(inti=first[u];i!=-1; i=Next[i]) { $             intv=e[i].v,a=e[i].a,b=e[i].b,t=e[i].t; -              -             if(a<t)Continue;//The open time is less than the time passed the              -             intnow=d[u]% (A +b);Wuyi             if(now+t<=a) {//now able to pass the case of the slack the                 if(d[v]>d[u]+t) d[v]=d[u]+T; -             } Wu             Else{ -                 intWait=a+b-now;//now need to wait for the case of the slack About                 if(d[v]>d[u]+wait+t) d[v]=d[u]+wait+T; $             }             -         } -     }     -      A } +  the intMain () { -     intKase=0; $      while(SCANF ("%d %d%d%d", &n,&m,&s,&t)! =EOF) { thememset (first,-1,sizeof(first)); theEcnt=0; the          the          while(m--){ -             intu,v,a,b,t; inCin>>u>>v>>a>>b>>T; the Addedge (u,v,a,b,t); the         } About Dijkstra (s); the          theprintf"Case %d:",++Kase); theprintf"%d\n", D[t]); +     } -     return 0; the}
View Code

UVa 12661 Funny Car Racing "Dijkstra"

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.