bzoj1614[usaco2007 jan]telephone Lines Erection Telephone Line
Test instructions
n nodes, node 1th is connected to the Internet and now needs to connect the entire graph to the network. There is a free connection on the K-bar, and the final total cost is the maximum of all the side charges, and the minimum total cost is calculated. n≤10000
Exercises
Second, the cost of the double-edge is greater than the length of the two points recorded as 1, otherwise recorded as 0, to find the shortest way, if the distance to a point more than K, you need to add the answer, continue to two points.
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 10017 #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{intT,w,y,n;}; E es[maxn* -];intESS,G[MAXN]; - voidPeintFintTintW) { -Es[++ess]= (e) {T,0, W,g[f]}; g[f]=ess; Es[++ess]= (e) {f,0, W,g[t]}; g[t]=ess; + } - BOOLINQ[MAXN];intD[maxn],n,m,k,ans; queue<int>Q; + BOOLSPFA () { A while(!q.empty ()) Q.pop (); memset (INQ,0,sizeof(INQ)); Inc (I,1, N) d[i]=INF; atinq[1]=1; Q.push (1); d[1]=0; - while(!Q.empty ()) { - intX=q.front (); Q.pop (); inq[x]=0; - for(intI=G[X];I;I=ES[I].N)if(d[es[i].t]>d[x]+ES[I].W) { -D[ES[I].T]=D[X]+ES[I].W;if(!inq[es[i].t]) inq[es[i].t]=1, Q.push (es[i].t); - } in } - if(d[n]>k)return 0;Else return 1; to } + BOOLCheckintx) { -Inc (I,1, ESS)if(es[i].y<=x) es[i].w=0;Elsees[i].w=1; the returnSPFA (); * } $ intMain () {Panax NotoginsengN=read (); M=read (); K=read ();intL=0, r=0; ans=-1; -Inc (I,1, m) {intA=read (), B=read (), C=read (); PE (A,B,C); R=Max (r,c);} the while(l<=R) { + intMid= (l+r) >>1;if(Check (mid)) ans=mid,r=mid-1;ElseL=mid+1; A } theprintf"%d", ans);return 0; +}
20160811
bzoj1614[usaco2007 jan]telephone Lines Erection Telephone Line *