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 ar array
#define int long long
const int N = 305;
int d[N][N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin>>n>>m;
int s, t, u, v; cin>>s>>t>>u>>v;
memset(d, 63, sizeof d);
for(int i=1;i<=n;i++) d[i][i] = 0;
for(int i=0;i<m;i++){
int a, b, c; cin>>a>>b>>c;
d[a][b] = min(d[a][b], c);
d[b][a] = min(d[b][a], c);
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
int res = d[u][v];
//~ cout<<d[s][1]<<" "<<d[1][1]<<" "<<d[1][t]<<"\n";
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(d[s][i] + d[i][j] + d[j][t] == d[s][t]){
res = min(res, d[u][i] + d[j][v]);
res = min(res, d[u][j] + d[i][v]);
}
}
}
cout<<res<<"\n";
}
# | 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... |