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>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define int long long
#define ll long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+7;
const int N=1e5+5,M=1e4;
vector<pair<int,int>> g[N];
vector<int> djks(int s){
vector<int> dist(N,INF),used(N,0);
priority_queue<pair<int,int>> dq;
dq.push({0,s});
dist[s]=0;
while(!dq.empty()){
int a=dq.top().sc;
dq.pop();
if(used[a]) continue;
used[a]=1;
for(auto it: g[a]){
if(dist[it.fr]>dist[a]+it.sc){
dist[it.fr]=dist[a]+it.sc;
dq.push({-dist[it.fr],it.fr});
}
}
}
return dist;
}
void solve(){
int n,m;cin>>n>>m;
int S,T,U,V;
cin>>S>>T>>U>>V;--S,--T,--U,--V;
for(int i=0;i<m;i++){
int a,b,c;cin>>a>>b>>c;--a,--b;
g[a].pb({b,c});
g[b].pb({a,c});
}
vector<int> s=djks(S),t=djks(T),u=djks(U),v=djks(V);
int ans=INF;
vector<int> dpu(N,INF),dpv(N,INF);
vector<pair<int,int>> vec;
for(int i=0;i<n;i++){
if(s[i]+t[i]==s[T])
vec.pb({s[i],i});
}
sort(all(vec));
for(auto aaa: vec){
int i=aaa.sc;
dpu[i]=u[i];
dpv[i]=v[i];
for(auto it: g[i]){
if(t[i]+it.sc+s[it.fr]==s[T]){
dpu[i]=min(dpu[it.fr],dpu[i]);
dpv[i]=min(dpv[it.fr],dpv[i]);
}
}
ans=min(ans,dpu[i]+v[i]);
ans=min(ans,dpv[i]+u[i]);
}
//for(int i=0;i<n;i++) cout<<u[i]<<' ';
cout<<min(ans,u[V]);
}
main(){
//ios;
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Compilation message (stderr)
commuter_pass.cpp:72:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
72 | main(){
| ^~~~
commuter_pass.cpp: In function 'void fopn(std::string)':
commuter_pass.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | freopen((name+".out").c_str(),"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... |