Addicted to brush water
the previous two-point wording can not be qaq changed a kind of like everyone is more commonly used two points . The reason is not yet clear.
"The main topic"
Given a graph, you can reduce the Benquan of the K-bar to 0 and the minimum of the longest side of the path from 1 to N.
Ideas
The two-point answer, the minimum value of the longest edge, is X. For each check (x), we set the edge of the edge greater than X to 1, the edge weight is less than or equal to the x edge is set to 0, run SPFA, the result is equivalent to the minimum number of edges over the edge of X. If the SPFA result is >k, it is not feasible, otherwise it is feasible.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6#include <vector>7#include <queue>8 using namespacestd;9 Const intinf=1000000+5;Ten Const intmaxn= ++5; One structEdge A { - intTo,dis; - }; theVector<edge>E[MAXN]; - intn,p,k; - intINQUE[MAXN],DIS[MAXN]; - + voidAddedge (intUintVintW) - { + E[u].push_back (Edge) {v,w}); A E[v].push_back (Edge) {u,w}); at } - - voidInit () - { -scanf"%d%d%d",&n,&p,&k); - for(intI=1; i<=p;i++) in { - intu,v,w; toscanf"%d%d%d",&u,&v,&W); + Addedge (u,v,w); - } the } * $ intCheckintx)Panax Notoginseng { -queue<int>que; thememset (Inque,0,sizeof(Inque)); +memset (DIS,0x7f,sizeof(DIS)); Adis[1]=0, inque[1]=1; theQue.push (1); + while(!que.empty ()) - { $ intHead=Que.front (); Que.pop (); $inque[head]=0; - for(intI=0; I<e[head].size (); i++) - { the intnowlen,to=e[head][i].to; - if(e[head][i].dis>x) nowlen=1;Elsenowlen=0;Wuyi if(dis[head]+nowlen<Dis[to]) the { -dis[to]=dis[head]+Nowlen; Wu if(!Inque[to]) - { About Que.push (to); $inque[to]=1; - } - } - } A } + if(dis[n]>k)return 0;Else return 1; the } - $ voidSolve () the { the intlb=0, ub=inf,ans=-1; the while(lb<=UB) the { - intMid= (Lb+ub) >>1; in if(Check (mid)) ub=mid-1, ans=mid; the ElseLb=mid+1; the } Aboutprintf"%d\n", ans); the } the the intMain () + { - init (); the solve ();Bayi return 0; the}
"Spfa+ Two answers" bzoj1614-[Usaco2007 jan]telephone lines erecting telephone lines