This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pil pair<int,ll>
#define pli pair<ll,int>
using namespace std;
const int nmax=1e5+1;
const int mod=1e9+7;
int n,m,s,t,u,v;
ll ans=1e18;
ll dp[4][nmax];
ll d[2][nmax];
vector<pil> adj[nmax];
void dijk(int u,int t){
priority_queue<pli,vector<pli>,greater<pli>> q;
q.push({0,u});
dp[t][u]=0;
while(!q.empty()){
pli top=q.top();
q.pop();
if(top.fi>dp[t][top.se]) continue;
for(auto x : adj[top.se]){
if(dp[t][x.fi]>dp[t][top.se]+x.se){
dp[t][x.fi]=dp[t][top.se]+x.se;
q.push({dp[t][x.fi],x.fi});
}
}
}
}
void solve(int tt){
vector<pli> tmp;
for(int i=1;i<=n;i++){
if(dp[0][t]==dp[0][i]+dp[1][i]){
tmp.push_back({dp[tt][i],i});
}
}
sort(tmp.begin(),tmp.end());
for(auto x : tmp){
int pos=x.se;
d[0][pos]=dp[2][pos];
d[1][pos]=dp[3][pos];
for(auto c : adj[pos]){
if(dp[tt][c.fi]+c.se==dp[tt][pos]){
d[0][pos]=min(d[0][pos],d[0][c.fi]);
d[1][pos]=min(d[1][pos],d[1][c.fi]);
}
}
ans=min({ans,d[0][pos]+dp[3][pos],d[1][pos]+dp[2][pos]});
}
}
int main(){
if(fopen("test1.inp","r"))
{
freopen("test1.inp","r",stdin);
freopen("test1.out","w",stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(),cout.tie();
cin >> n >> m >> s >> t >> u >> v;
for(int i=1,x,y;i<=m;i++){
ll w;
cin >> x >> y >> w;
adj[x].push_back({y,w});
adj[y].push_back({x,w});
}
memset(dp,0x3f,sizeof(dp));
dijk(s,0);
dijk(t,1);
dijk(u,2);
dijk(v,3);
ans=dp[3][u];
// cout << ans << '\n';
memset(d,0x3f,sizeof(d));
solve(0);
solve(1);
cout << ans;
}
Compilation message (stderr)
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen("test1.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | freopen("test1.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |