#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define pii pair<long long, long long>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
ll n, m, s, t, u, v, a, b, c, d[305][305];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> s >> t >> u >> v;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(i==j)
d[i][j]=0;
else{
d[i][j]=LLONG_MAX;
d[j][i]=LLONG_MAX;
}
}
}
for(int i=0; i<m; i++){
cin >> a >> b >> c;
d[a][b]=c;
d[b][a]=c;
}
for(int caur=1; caur<=n; caur++){
for(int no=1; no<=n; no++){
for(int uz=1; uz<=n; uz++){
if(d[no][caur]!=LLONG_MAX && d[caur][uz]!=LLONG_MAX)
d[no][uz]=min(d[no][caur]+d[caur][uz], d[no][uz]);
}
}
}
ll ans=d[u][v];
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] ||
d[s][j]+d[i][j]+d[i][t]==d[s][t]){
ans=min({ans, d[u][i]+d[v][j], d[u][j]+d[v][i]});
}
}
}
cout << max((long long)0, ans) << '\n';
return 0;
}
# | 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... |