Descriptionrecently, the relationship between Elaxia and w** was particularly good, and they wanted to be together all day long, but the university was so nervous that they had to arrange for two people to spend time with each other properly. Elaxia and w** every day to travel between the dorm and the laboratory, they want to save time under the premise of walking together as long as possible. It is now known that the number of dormitories and laboratories where Elaxia and w** are located, as well as the school map: There are n intersections on the map, M roads, and it takes a certain amount of time to pass each route. Specifically, the longest common path between two pairs of points is required in a non-aligned graph. InputFirst line: two integers n and m (meaning such as title description). The second line: four integers x1, y1, x2, y2 (1≤x1≤n,1≤y1≤n,1≤x2≤n,1≤≤n), respectively, representing Elaxia dormitories and laboratory and w** quarters and laboratory markings (two pairs of points x1,y1 and X2,y2 respectively). Next m line: three integers per line, u, V, L (1≤u≤n,1≤v≤n,1≤l≤10000), there is a road between table U and V, the time required to pass this road is L. Out-of-Gegger::: A line, an integer representing the time of two people per day (that is, the length of the longest public path). Outputa row, an integer that represents the time of day two people together (that is , the length of the longest common path)
Find out the intersection of the shortest-circuit diagram of X1-y1,x2-y2 and find the longest chain is the answer, because test instructions unknown also to the X2,y2 exchange again calculate again
#include <cstdio>#include<queue>intn,m,x1,y1,x2,y2,ans=0;Const intn=1550*1550;intes[n],enx[n],ev[n],e0[1550],l[1550],ep=2;BOOLD1[n],d2[n],d3[n],inch[1550],a1[1550],a2[1550],ed1[1550],ed2[1550];intins[1550];voidSpintSintt) { for(intI=1; i<=n;i++) l[i]=2147483647; L[s]=0; Std::queue<int>Q; Q.push (s); while(!Q.empty ()) { intw=Q.front (); Q.pop (); inch[w]=0; for(intI=e0[w];i;i=Enx[i]) { intu=Es[i]; if(l[w]+ev[i]<L[u]) {L[u]=l[w]+Ev[i]; if(!inch[u])inch[u]=1, Q.push (U); } } }}BOOLDFS1 (intW) { if(w==y1)return 1; if(Ed1[w])returnA1[w]; BOOLt=0; for(intI=e0[w];i;i=Enx[i]) { intu=Es[i]; if(l[w]+ev[i]==L[u]) T|= (d1[i]=dfs1 (u)); } A1[w]=t;ed1[w]=1; returnt;}BOOLDFS2 (intW) { if(W==y2)return 1; if(Ed2[w])returnA2[w]; BOOLt=0; for(intI=e0[w];i;i=Enx[i]) { intu=Es[i]; if(l[w]+ev[i]==L[u]) T|= (d2[i]=d3[i^1]=dfs2 (u)); } A2[w]=t;ed2[w]=1; returnt;}voidChkBOOL*D1,BOOL*D2) {Std::queue<int>Q; for(intI=1; i<=n;i++)if(!Ins[i]) Q.push (i); while(!Q.empty ()) { intw=Q.front (); Q.pop (); for(intI=e0[w];i;i=Enx[i]) { if(!d1[i]| |! D2[i])Continue; intu=Es[i]; if(L[w]+ev[i]>l[u]) l[u]=l[w]+Ev[i]; if(!--Ins[u]) q.push (U); } } for(intI=1; i<=n;i++){ if(L[i]>ans) ans=L[i]; L[i]=0; }}intMain () {scanf ("%d%d",&n,&m); scanf ("%d%d%d%d",&x1,&y1,&x2,&y2); for(intI=0, a,b,c;i<m;i++) {scanf ("%d%d%d",&a,&b,&c); ES[EP]=b;enx[ep]=e0[a];ev[ep]=c;e0[a]=ep++; ES[EP]=a;enx[ep]=e0[b];ev[ep]=c;e0[b]=ep++; } sp (X1,Y1); DFS1 (x1); SP (X2,Y2); DFS2 (x2); for(intI=1; i<=n;i++) {L[i]=0; for(intj=e0[i];j;j=Enx[j]) { if(D1[j]&d2[j]) + +Ins[es[j]]; }} chk (D1,D2); for(intI=1; i<=n;i++) {L[i]=0; for(intj=e0[i];j;j=Enx[j]) { if(D1[j]&d3[j]) + +Ins[es[j]]; }} chk (D1,D3); printf ("%d", ans); return 0;}
bzoj1880 [Sdoi2009]elaxia's route