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 mn 100009
#define pb push_back
using namespace std;
long long n, m, S, T, U, V;
long long f[mn];
vector<long long> v[mn], l[mn];
void Dij(long long k, long long *D){
priority_queue<pair<long long,long long> > q;
q.push({0,k});
for(long long i = 1; i <= n; i++)
D[i] = 1e18, f[i] = 0;
D[k] = 0;
while(q.size()){
long long x = q.top().second;
q.pop();
if(f[x]) continue;
f[x] = 1;
for(long long i = 0; i < v[x].size(); i++){
if(f[v[x][i]] == 0 &&
D[v[x][i]] > D[x] + l[x][i]){
D[v[x][i]] = D[x] + l[x][i];
q.push({-D[v[x][i]], v[x][i]});
}
}
}
}
long long du[mn], dv[mn], ds[mn], dt[mn], mindu[mn], mindv[mn];
void specDIJ(){
priority_queue<pair<long long,long long> > q;
q.push({0,T});
for(long long i = 1; i <= n; i++)
dt[i] = 1e18, mindu[i] = du[i], mindv[i] = dv[i] ,f[i] = 0;
dt[T] = 0;
while(q.size()){
long long x = q.top().second;
q.pop();
if(f[x]) continue;
f[x] = 1;
for(long long i = 0; i < v[x].size(); i++){
long long p = v[x][i];
if(dt[p] > dt[x] + l[x][i]){
dt[p] = dt[x] + l[x][i];
mindu[p] = min(mindu[x], du[p]);
mindv[p] = min(mindv[x], dv[p]);
q.push({-dt[p], p});
}
if(dt[p] == dt[x] + l[x][i]){
mindu[p] = min(mindu[p], mindu[x]);
mindv[p] = min(mindv[p], mindv[x]);
}
}
}
}
main(){
cin >> n >> m >> S >> T >> U >> V;
for(long long i = 0 ;i < m; i++){
long long a, b, c;
cin >> a>> b >> c;
v[a].pb(b);
v[b].pb(a);
l[a].pb(c);
l[b].pb(c);
}
Dij(S,ds);
Dij(U,du);
Dij(V,dv);
specDIJ();
long long ans = 1e18;
for(long long i = 1; i <= n; i++){
if(ds[i] + dt[i] == ds[T]){
ans = min(ans, dv[i] + mindu[i]);
ans = min(ans, du[i] + mindv[i]);
}
}
cout << min(ans, du[V]) << endl;
}
Compilation message (stderr)
commuter_pass.cpp: In function 'void Dij(long long int, long long int*)':
commuter_pass.cpp:19:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i = 0; i < v[x].size(); i++){
~~^~~~~~~~~~~~~
commuter_pass.cpp: In function 'void specDIJ()':
commuter_pass.cpp:40:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i = 0; i < v[x].size(); i++){
~~^~~~~~~~~~~~~
commuter_pass.cpp: At global scope:
commuter_pass.cpp:55:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | 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... |