bzoj3538[usaco2014 open]dueling gps*

Source: Internet
Author: User

bzoj3538[usaco2014 open]dueling GPS

Test Instructions:Give you a graph of n points, set the initial position to 1, and the end position to N. There are two GPS positioning systems, respectively, that pass the time of the edge I as pi, and QI. Every time you go to a side, if a system thinks that this side of the walk is not the shortest one it thinks, it will be warned once. If this side of the walk is not within the shortest range considered by the two systems, it will be subject to 2 warnings. The minimum number of warnings to be received. n≤10000, number of sides ≤50000The following:According to the Benquan of two GPs to find the shortest way, and then enumerate each edge, the edge of the edge contingency for its warning number, and then to find the most short-circuit. Determine if the edge is not the shortest condition is whether the dis[es[i].f]+es[i].w==dis[es[i].t].Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineMAXN 100107 #defineINF 0X3FFFFFFF8 using namespacestd;9 TenInlineintRead () { One     CharCh=getchar ();intf=1, x=0; A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); -     returnf*x; the } - structe{intF,t,w,n;} es[maxn*5];intg[maxn],ess; - voidPeintFintTintW) {es[++ess]= (e) {f,t,w,g[f]}; g[f]=ess;} - intn,m,a[2][maxn*5],b[maxn*5],d[2][MAXN]; queue<int>q;BOOLINQ[MAXN]; + voidSPFA (intSinto) { -      while(!q.empty ()) Q.pop (); memset (INQ,0,sizeof(INQ)); Inc (I,1, N) d[o][i]=INF; +Q.push (s); inq[s]=1; d[o][s]=0; A      while(!Q.empty ()) { at         intX=q.front (); Q.pop (); inq[x]=0; -          for(intI=G[X];I;I=ES[I].N)if(d[o][x]+es[i].w<d[o][es[i].t]) { -D[O][ES[I].T]=D[O][X]+ES[I].W;if(!inq[es[i].t]) Q.push (es[i].t), inq[es[i].t]=1; -         } -     } - } in intMain () { -N=read (); M=read (); Inc (I,1, m) {intX=read (), Y=read (), Z=read (); PE (Y,X,Z); a[0][i]=z; a[1][i]=read ();} toSPFA (N,0); Inc (I,1, m) es[i].w=a[1][i]; SPFA (N,1); +Inc (I,1, M) {Inc (J,0,1)if(d[j][es[i].f]+a[j][i]>d[j][es[i].t]) b[i]++; es[i].w=b[i];} -SPFA (N,0); printf"%d", d[0][1]);return 0; the}

20160909

bzoj3538[usaco2014 open]dueling gps*

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.