#include <bits/stdc++.h>
#pragma GCC optimize ("O3,unroll-loops")
#pragma GCC target ("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
const int64_t N=100005;
vector<pair<int64_t,int64_t>> mas[N];
int64_t dS[N];
int64_t dT[N];
int64_t dV[N];
int64_t dU[N];
int64_t n,m;
int64_t s,t;//commuter pass
int64_t u,v;
void dijkstra(int64_t start, int64_t* dist){
    priority_queue<pair<int64_t,int64_t>,vector<pair<int64_t,int64_t>>,greater<pair<int64_t,int64_t>>> pq;
    dist[start]=0;
    pq.push({0,start});
    while(!pq.empty()){
        int64_t x=pq.top().second;
        pq.pop();
        for(auto p:mas[x]){
            if(dist[x]+p.second<dist[p.first]){
                dist[p.first]=dist[x]+p.second;
                pq.push({dist[p.first],p.first});
            }
        }
    }
}
void dijkstra2(int64_t start, int64_t* dist){
    priority_queue<pair<int64_t,int64_t>,vector<pair<int64_t,int64_t>>,greater<pair<int64_t,int64_t>>> pq;
    dist[start]=0;
    pq.push({0,start});
    while(!pq.empty()){
        int64_t x=pq.top().second;
        pq.pop();
        for(auto p:mas[x]){
            int64_t cost=p.second;
            if(dS[x]+dT[x]==dS[t]&&dS[p.first]+dT[p.first]==dS[t]){
                cost=0;
            }
            if(dist[x]+cost<dist[p.first]){
                dist[p.first]=dist[x]+cost;
                pq.push({dist[p.first],p.first});
            }
        }
    }
}
int64_t df[305][305];
void floyd(){
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                df[i][j]=min(df[i][j],df[i][k]+df[k][j]);
            }
        }
    }
}
void solve(){
    cin>>n>>m;
    for(int64_t i=0;i<=n;i++){
        dS[i]=LLONG_MAX/4;
        dT[i]=LLONG_MAX/4;
        dV[i]=LLONG_MAX/4;
        dU[i]=LLONG_MAX/4;
        for(int j=0;j<=n;j++){
            df[i][j]=LLONG_MAX/4;
            if(i==j){
                df[i][j]=0;
            }
        }
    }
    cin>>s>>t;
    cin>>u>>v;
    for(int64_t i=0;i<m;i++){
        int64_t x,y,c;
        cin>>x>>y>>c;
        mas[x].push_back({y,c});
        mas[y].push_back({x,c});
        df[x][y]=c;
        df[y][x]=c;
    }
    floyd();
    int64_t ans=df[u][v];
    for(int x=1;x<=n;x++){
        for(int y=1;y<=n;y++){
            if(df[s][t]==df[s][x]+df[x][y]+df[y][t]){
                ans=min(ans,df[u][x]+df[y][v]);
            }
        }
    }
    cout<<ans<<'\n';
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
    int64_t t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |