http://www.lydsy.com/JudgeOnline/problem.php?id=3575
Total bright The second question is always more difficult than the third question ...
Well, that's not a clue.
I heard that most of the data can be lost by the civil branch.
We have found that the path after the cut-off must be the following: edges on several non-shortest paths, edges on several original shortest paths, and end points along the original shortest path, starting point
We find that we do not go to the original shortest path of an interval, and the deleted edges must be on this interval
We enumerate the edges in order, and then start from the starting point of this edge to run SPFA, do not take the deleted edge (do not take the empty dis array, here is the key, DIS has monotonicity). The point P (p must be after the deleted edge) from this point to the other shortest way, and then add the length of the whole path to the balance tree together with P. Out of the balance tree take the minimum length of the edge, if it does the corresponding P-point (shortest path) and not after the deleted edge, the edge is removed. If the balance tree is empty, then output-1
Too bad! ~ ~ ~
#include <cstdio>#include<cstdlib>#include<iostream>#include<fstream>#include<algorithm>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<map>#include<utility>#include<Set>#include<bitset>#include<vector>#include<functional>#include<deque>#include<cctype>#include<climits>#include<complex>#include<cassert>//#include <bits/stdc++.h> for Cf,uoj, but not for POJ using namespaceStd;typedefLong LongLl;typedefDoubleDb;typedef pair<int,int>Pii;typedef pair<DB,DB>Pdd;typedef Complex<DB>cp;typedef Vector<int>VI;#defineMmSt (a,v) memset (A,v,sizeof (a))#defineMmcy (A, B) memcpy (A,b,sizeof (a))#defineFill (a,l,r,v) Fill (a+l,a+r+1,v)#defineRe (I,A,B) for (i= (a); i<= (b); i++)#defineRed (i,a,b) for (i= (a); i>= (b); i--)#defineFi first#defineSe Second#defineMP (A, b) Make_pair (A, B)#definePB (a) push_back (a)#defineSF scanf#definePF printf#defineBoth (k) (1<< (k))#defineSZ (x) (int (x.size ()))#defineAll (x) (x). Begin (), (x). End ()#defineIRE (I,V,X) for (I=0,v=i<sz (x)? X[i]:0;i<sz (x); V=x[++i])Template<classT>inline T Sqr (t x) {returnx*x;} Template<classT>inlinevoidUpmin (T &t,t tmp) {if(t>tmp) t=tmp;} Template<classT>inlinevoidUpmax (T &t,t tmp) {if(t<tmp) t=tmp;} InlineintSGN (DB x) {if(ABS (x) <1e-9)return 0;return(x>0)?1:-1;}ConstDB Pi=acos (-1.0);intGint () {intres=0;BOOLneg=0;CharZ; for(Z=getchar (); z!=eof && z!='-'&&!isdigit (z); z=GetChar ()); if(z==eof)return 0; if(z=='-') {neg=1; z=GetChar ();} for(; z!=eof && isdigit (z); res=res*Ten+z-'0', z=GetChar ()); return(neg)?-Res:res; }ll Gll () {LL res=0;BOOLneg=0;CharZ; for(Z=getchar (); z!=eof && z!='-'&&!isdigit (z); z=GetChar ()); if(z==eof)return 0; if(z=='-') {neg=1; z=GetChar ();} for(; z!=eof && isdigit (z); res=res*Ten+z-'0', z=GetChar ()); return(neg)?-Res:res; }Const intmaxn=100100;Const intmaxm=200100;intn,m,l;intNOW,INFO[MAXN];structtedge{intV,cost,next;} EDGE[MAXM];intE[MAXM],LEN[MAXM],G[MAXM],PRE[MAXM],SUC[MAXM],POS[MAXN],BAN[MAXM],VAL[MAXN];voidAddedge (intUintVintCost) {edge[++now]= (Tedge) {v,cost,info[u]};info[u]=Now ;} Multiset<PII>S;intDis[maxn],ci,vis[maxn];queue<int>que;intTOP,STA[MAXN];voidSPFA (intDintSourceintLim) {inti; while(!que.empty ()) Que.pop (); Top=0; CI++; Dis[source]=D; Que.push (source); Vis[source]=CI; while(!Que.empty ()) { intu=Que.front (), V,cost;que.pop (); Vis[u]=0; for(I=info[u],v=edge[i].v,cost=edge[i].cost;i;i=edge[i].next,v=edge[i].v,cost=edge[i].cost)if(!Ban[i])if(pos[v]>=Lim) {if(vis[v]!=ci) vis[v]=ci,sta[++top]=v,val[v]=dis[u]+cost+Suc[pos[v]]; Elseupmin (Val[v],dis[u]+cost+Suc[pos[v]]); } Else if(dis[u]+cost<Dis[v]) {Dis[v]=dis[u]+Cost ; if(VIS[V]!=CI) Que.push (v), vis[v]=CI; }} re (I,1, top) S.insert (MP (Val[sta[i]],sta[i)); }intMain () {Freopen ("road.in","R", stdin); Freopen ("Road.out","W", stdout); inti; N=gint (); M=gint (), l=Gint (); Re (i,1, m) {intU=gint (), V=gint (), cost=gint (); Addedge (u,v,cost);} g[1]=1; Re (i,1, l) e[i]=gint (), len[i]=edge[e[i]].cost,g[i+1]=edge[e[i]].v; Re (i,1, L +1) pos[g[i]]=i; Re (i,2, L +1) pre[i]=pre[i-1]+len[i-1]; Red (i,l,1) suc[i]=suc[i+1]+Len[i]; MmSt (DIS,0x3f); Re (i,1, L) {Ban[e[i]]=1; SPFA (Pre[i],g[i],i+1); Ban[e[i]]=0; while(! S.empty () && pos[s.begin ()->se]<=i) S.erase (S.begin ()); if(S.empty ()) PF ("-1\n");ElsePF ("%d\n", S.begin ()FI); } return 0; }View Code
BZOJ3575[HNOI2014] Road Jam