Give a graph and S, T, each time delete an edge, ask each deletion after the s to t the shortest path is changed. Asked to be independent of each other.
The shortest road network is built from S, t respectively, and then cut on the shortest road network.
If the side of the inquiry is on the shortest road network and the cutting edge changes, it will not change.
#include <iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>using namespacestd;#defineSZ 456789intN;namespacespfa{intm=0, Vb[sz],dst[sz],fst[sz],nxt[sz],q[sz],d1[sz],d2[sz],vc[sz],ids[sz],f1[sz],f2[sz];BOOLIq[sz];voidAD_DL (intAintBintCintID) { ++m; Nxt[m]=fst[a]; Fst[a]=m; Vb[m]=b; Vc[m]=c; ids[m]=ID;}voidGETSP (int* D,int* F,intS) { intH=0, t=1; q[0]=R; for(intI=1; i<=n;i++) d[i]=1000000000, iq[i]=0; C[t]=0; iq[s]=1; while(h!=t) {intCur=q[h++]; h&=524287; for(intE=fst[cur];e;e=Nxt[e]) { intB=vb[e],c=Vc[e]; if(D[B]<=D[CUR]+C)Continue; D[B]=d[cur]+c; f[b]=cur; if(!iq[b]) q[t++]=b; T&=524287; } Iq[cur]=0; }}}namespacecute{intm=0, Vb[sz],fst[sz],nxt[sz];voidAD_DL (intAintb) { ++m; Nxt[m]=fst[a]; Fst[a]=m; vb[m]=b;}voidAddl (intAintb) {ad_dl (A, b); Ad_dl (b,a);}intDfn[sz],low[sz],c=0;voidTarjan (intXintf) {Dfn[x]=low[x]=++b; for(intE=fst[x];e;e=Nxt[e]) { intb=Vb[e]; if(!Dfn[b]) {Tarjan (b,x); LOW[X]=min (low[b],low[x]); } Else if(b!=f) low[x]=min (low[x],dfn[b]); }}}intXs[sz],ys[sz],zs[sz];BOOL out[SZ];#defineFO (x) {freopen (#x ".", "R", stdin), Freopen (#x ". Out", "w", stdout);}intMain () {FO (school)using namespaceSPFA; ints,t,m; scanf ("%d%d%d%d",&n,&m,&s,&t); for(intI=1; i<=m;i++) { intx, Y, Z scanf ("%d%d%d",&x,&y,&z); Xs[i]=x; Ys[i]=y; zs[i]=Z; SPFA::AD_DL (X,y,z,i); SPFA::AD_DL (Y,x,z,i); } getsp (D1,f1,s); GETSP (d2,f2,t); for(intI=1; i<=n;i++) dst[i]=d1[i]+D2[i]; intTar=Dst[t]; for(intI=1; i<=m;i++) { BOOLok=1; if(d1[xs[i]]+d2[ys[i]]+zs[i]==tar) cute::addl (xs[i],ys[i]); Else if(d2[xs[i]]+d1[ys[i]]+zs[i]==tar) cute::addl (xs[i],ys[i]); Elseok=0; if(!ok) out[i]=1; } for(intI=1; i<=n;i++)if(!cute::d fn[i]) Cute::tarjan (i,0); using namespacecute; intQ scanf"%d",&q); while(q--) { inte; scanf ("%d",&e); intx=xs[e],y=Ys[e]; if(! out[e]&& (low[x]>dfn[y]| | LOW[Y]>DFN[X]) puts ("No"); ElsePuts"Yes"); }}
The shortest-circuited topic of a cut edge