1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| # include <algorithm> # include <iostream> # include <cstring> # include <cstdio> # include <vector> # include <queue> # include <cmath> # define R register # define LL long long
using namespace std;
struct zx{int v,w,pre;}ed[2000010]; queue <int> q; int n,m,x,y,z,e,h[3010],dis[5][3010],s1,t1,s2,t2,ans; bool v[3010];
template <typename T> void in(R T &a){ R char c = getchar();R T x=0,f=1; while(!isdigit(c)) {if(c == '-') f=-1; c=getchar();} while(isdigit(c)) x=(x<<1)+(x<<3)+c-'0',c = getchar(); a=x*f; }
inline void maxx(R int &a,const int b){a>b? 0:a=b;} inline void minn(R int &a,const int b){a<b? 0:a=b;} inline void add(R int x,R int y,R int z){ ed[++e] = (zx){y,z,h[x]}; h[x] = e; }
inline void SPFA(R int s,R int dis[]){ q.push(s); dis[s] = 0; while(!q.empty()){ R int x = q.front(); v[x] = 0; q.pop(); for(R int i=h[x]; i; i=ed[i].pre){ R int p = ed[i].v; if(dis[x]+ed[i].w<dis[p]){ dis[p] = dis[x]+ed[i].w; if(!v[p]) v[p] = 1,q.push(p); } } } }
inline void SPFAA(R int s,R int dis[]){ q.push(s); dis[s] = 0; while(!q.empty()){ R int x = q.front(); v[x] = 0; q.pop(); for(R int i=h[x]; i; i=ed[i].pre){ R int p = ed[i].v; if(dis[x]+ed[i].w>dis[p]){ dis[p] = dis[x]+ed[i].w; if(!v[p]) v[p] = 1,q.push(p); } } } }
inline int youngsc(){ in(n);in(m); in(s1),in(t1),in(s2),in(t2); memset(dis,127/3,sizeof(dis)); for(R int i=1; i<=m; ++i) { in(x),in(y),in(z); add(x,y,z); add(y,x,z); } SPFA(s1,dis[1]); SPFA(t1,dis[2]); SPFA(s2,dis[3]); SPFA(t2,dis[4]); memset(dis[0],-127/3,sizeof(dis[0])); for(R int i=1; i<=n; ++i) { for(R int j=h[i]; j; j=ed[j].pre) { R int p = ed[j].v; if(dis[1][i]+ed[j].w+dis[2][p] == dis[1][t1]) { if(dis[3][i]+ed[j].w+dis[4][p] == dis[3][t2]) add(i+n,p+n,ed[j].w); else add(i+n,p+n,0); } } } SPFAA(s1+n,dis[0]); maxx(ans,dis[0][t1+n]);
for(R int i=1; i<=n; ++i) h[i+n] = 0;
memset(dis[0],-127/3,sizeof(dis[0])); for(R int i=1; i<=n; ++i) { for(R int j=h[i]; j; j=ed[j].pre) { R int p = ed[j].v; if(dis[1][i]+ed[j].w+dis[2][p] == dis[1][t1]) { if(dis[3][p]+ed[j].w+dis[4][i] == dis[3][t2]) add(i+n,p+n,ed[j].w); else add(i+n,p+n,0); } } } SPFAA(s1+n,dis[0]); maxx(ans,dis[0][t1+n]); printf("%d",ans); } int yg = youngsc(); int main(){;}
|