This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;
typedef pair< lo,PIII > PIIII;
typedef pair< lo,PIIII > PIIIII;
#define fi first
#define se second
#define mp make_pair
#define int long long
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,u,v,s,visit[li],d[li],vis[li],deg[li],cost[li],cost1[li],mini[li],mini1[li],ans=inf;
int cev;
vector<PII> vec[li];
inline void sp(){
priority_queue<PII> pq;
pq.push({0,t});
while(pq.size()){
int node=pq.top().se;
int co=-pq.top().fi;
pq.pop();
if(vis[node])continue;
vis[node]=1;
d[node]=co;
for(int i=0;i<(int)vec[node].size();i++){
int go=vec[node][i].fi;
int ind=vec[node][i].se;
pq.push({-co-a[ind],go});
}
}
//~ cout<<d[s]<<endl;
memset(vis,0,sizeof(vis));
pq.push({0,s});
while(pq.size()){
int node=pq.top().se;
int co=-pq.top().fi;
pq.pop();
if(vis[node])continue;
vis[node]=1;
deg[node]=co;
for(int i=0;i<(int)vec[node].size();i++){
int go=vec[node][i].fi;
int ind=vec[node][i].se;
//~ cout<<go<<" : : "<<co<<" : : "<<d[go]<<" : : "<<a[ind]<<endl;
if(d[go]+co+a[ind]==d[s])visit[ind]=1;
pq.push({-co-a[ind],go});
}
}
memset(vis,0,sizeof(vis));
pq.push({0,u});
while(pq.size()){
int node=pq.top().se;
int co=-pq.top().fi;
pq.pop();
if(vis[node])continue;
vis[node]=1;
cost[node]=co;
for(int i=0;i<(int)vec[node].size();i++){
int go=vec[node][i].fi;
int ind=vec[node][i].se;
//~ cout<<go<<" : : "<<co<<" : : "<<d[go]<<" : : "<<a[ind]<<endl;
if(d[go]+co+a[ind]==d[s])visit[ind]=1;
pq.push({-co-a[ind],go});
}
}
memset(vis,0,sizeof(vis));
pq.push({0,v});
while(pq.size()){
int node=pq.top().se;
int co=-pq.top().fi;
pq.pop();
if(vis[node])continue;
vis[node]=1;
cost1[node]=co;
for(int i=0;i<(int)vec[node].size();i++){
int go=vec[node][i].fi;
int ind=vec[node][i].se;
//~ cout<<go<<" : : "<<co<<" : : "<<d[go]<<" : : "<<a[ind]<<endl;
if(d[go]+co+a[ind]==d[s])visit[ind]=1;
pq.push({-co-a[ind],go});
}
}
priority_queue<PIIIII> pq1;
memset(vis,0,sizeof(vis));
pq1.push({0,{-cost[s]-cost1[s],{-cost[s],{-cost1[s],s}}}});
while(pq1.size()){
//~ int node=pq1.top().se.se;
int node=pq1.top().se.se.se.se;
int co2=-pq1.top().se.se.se.fi;
int co1=-pq1.top().se.se.fi;
int cooo=-pq1.top().se.fi;
int co=-pq1.top().fi;
pq1.pop();
if(vis[node])continue;
vis[node]=1;
ans=min(ans,co1+co2);
for(int i=0;i<(int)vec[node].size();i++){
int go=vec[node][i].fi;
int ind=vec[node][i].se;
if(d[go]+co+a[ind]==d[s] && deg[node]+d[go]+a[ind]==deg[t]){
pq1.push({-co-a[ind],{-min(co1,cost[go])-min(co2,cost1[go]),{-min(co1,cost[go]),{-min(co2,cost1[go]),go}}}});
}
}
}
}
main(void){
scanf("%lld %lld",&n,&m);
scanf("%lld %lld",&s,&t);
scanf("%lld %lld",&u,&v);
FOR mini[i]=inf;
FOR mini1[i]=inf;
for(int i=1;i<=m;i++){
int x,y;
scanf("%lld %lld %lld",&x,&y,&a[i]);
vec[x].pb({y,i});
vec[y].pb({x,i});
}
sp();
//~ int ans=inf;
//~ FOR{
//~ ans=min(ans,mini[i]+mini1[i]);
//~ ////~ cout<<mini[i]+mini1[i]<<" : : "<<mini[i]<<" : : "<<mini1[i]<<endl;
//~ }
ans=min(ans,cost[v]);
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
commuter_pass.cpp: In function 'void sp()':
commuter_pass.cpp:113:7: warning: unused variable 'cooo' [-Wunused-variable]
int cooo=-pq1.top().se.fi;
^~~~
commuter_pass.cpp: At global scope:
commuter_pass.cpp:130:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(void){
^
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:131:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&n,&m);
~~~~~^~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:132:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&s,&t);
~~~~~^~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:133:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&u,&v);
~~~~~^~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:138:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld",&x,&y,&a[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |