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 int long long
const int N = 1e5 + 12;
int n, m, s, f, l, r, x, y, z, res, dis[505][505];
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
cin>>n>>m;
cin>>s>>f;
cin>>l>>r;
memset(dis, 63, sizeof dis);
for(int i=1; i<=n; i++)dis[i][i] = 0;
while(m--){
cin>>x>>y>>z;
dis[x][y] = min(dis[x][y], z);
dis[y][x] = min(dis[y][x], z);
}
for(int k=1; k<=n; k++){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
}
res = dis[l][r];
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(dis[s][i] + dis[i][j] + dis[j][f] == dis[s][f]){
res = min(res, dis[l][i] + dis[j][r]);
res = min(res, dis[l][j] + dis[i][r]);
}
}
}
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... |