Description
As we all know, home is far from school. As a result, every day to calculate the time to start, to ensure that the school bell before the second to reach the university.
Unfortunately, the city is on the road recently. This leads to some roads that may be impassable and may result in lateness.
Not going to change his departure time, now he tells you he's going through every road, he wants to know if a road is repaired, can he avoid being late?
Input
The first line enters two positive integers, representing the points (intersections) and the number of edges (roads), respectively.
The second line enters two positive integers, indicating that the home label is the school label.
The next line, with three integers per line, indicates that there is a connected road, and the time it takes to go through that road is.
The next integer that represents the number of queries.
The last line, a positive integer for each line, indicates if the side of the section is being repaired and will be able to get to school on time.
Output
The output line.
For each inquiry, if you can go to school on time output a string, otherwise output.
(Strings are strictly matched, without double quotes)
Sample Input
8 11
1 8
1 2 3
1 3 1
2 3 1
2 4 5
2 5 1
4 5 4
3 5 2
5 6 4
6 7 5
6 8 2
7 8 5
5
2
3
8
4
10
Sample Output
No
Yes
No
Yes
No
HINT
To ensure that the shortest short-circuit length of the source point to any point is not exceeded.
Solution
First find the map of the shortest path. If an edge is a cut of a side image, you can't avoid being late.
#include <cmath>#include<ctime>#include<stack>#include<queue>#include<cstdio>#include<vector>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>#defineN 40005#defineM 400005using namespaceStd;typedefLong Longll;structgraph{intnxt,to,n;ll W;} E[m],e1[m];ll Dis[n];intg[n],g1[n],dfn[n],low[n],n,m,s,t,cnt;BOOLB[m],f[n],inq[n];queue<int>Q;inlineintRead () {intret=0;CharC=GetChar (); while(!isdigit (c)) c=GetChar (); while(IsDigit (c)) {ret= (ret<<1) + (ret<<3) +c-'0'; C=GetChar (); } returnret;} InlinevoidAdde (intIintXinty) {e1[++cnt].nxt=g1[x];g1[x]=CNT; E1[cnt].to=y;e1[cnt].n=i;} InlinevoidAddedge (intIintXintYintz) {e[++cnt].nxt=g[x];g[x]=CNT; E[cnt].to=y;e[cnt].w= (LL) (z); e[cnt].n=i;} InlinevoidSPFA (intu) { for(intI=1; i<=n;++i) dis[i]= (ll) (1e+7); Q.push (U);d Is[u]=0; inq[u]=true; while(!Q.empty ()) {u=q.front (); Q.pop (); inq[u]=false; for(intI=g[u];i;i=e[i].nxt)if(dis[e[i].to]<0|| dis[u]+e[i].w<Dis[e[i].to]) {Dis[e[i].to]=dis[u]+E[I].W; if(!Inq[e[i].to]) {Q.push (e[i].to); Inq[e[i].to]=true; }}}}inlinevoidBFsintu) {memset (INQ,0,sizeof(INQ)); CNT=0; Q.push (u); inq[u]=true; while(!Q.empty ()) {u=Q.front (); Q.pop (); for(intI=g[u];i;i=e[i].nxt)if(dis[e[i].to]+e[i].w==Dis[u]) {Adde (e[i].n,e[i].to,u); Adde (e[i].n,u,e[i].to); if(!Inq[e[i].to]) {Q.push (e[i].to); Inq[e[i].to]=true; }}}}inlinevoidTarjan (intUintf) {Dfn[u]=low[u]=++CNT; for(intI=g1[u];i;i=e1[i].nxt)if(!Dfn[e1[i].to]) {Tarjan (e1[i].to,u); Low[u]=min (low[u],low[e1[i].to]); if(Low[e1[i].to]>dfn[u]) b[e1[i].n]=true; } Else if(e1[i].to!=f) Low[u]=min (low[u],dfn[e1[i].to]);} Inlinevoidinit () {n=read (); m=read (); S=read (); t=read (); for(intI=1, x,y,z;i<=m;++i) {x=read (); Y=read (); z=read (); Addedge (i,x,y,z); Addedge (i,y,x,z); } SPFA (s); BFS (t); Tarjan (s),0); intq=read (); while(q--){ if(B[read ()]) puts ("No"); ElsePuts"Yes"); }}intMain () {Freopen ("school.in","R", stdin); Freopen ("School.out","W", stdout); Init (); Fclose (stdin); Fclose (stdout); return 0;}
[Daily Training]school