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 LL long long
using namespace std;
LL n,m,A,B,C,D,a[305][305], res, oo = 1e15;
int main() {
//freopen(".inp","r",stdin);
cin >> n >> m >> A >> B >> C >> D;
for(int i = 1; i <= n; ++ i) {
for(int j = 1; j <= n; ++ j) if( i != j ) a[i][j] = oo;
}
LL u,v,w;
for(int i = 1; i <= m ;++ i) {
cin >> u >> v >> w;
a[u][v] = a[v][u] = min( a[u][v], w );
}
for(int u = 1; u <= n; ++ u) {
for(int i = 1; i <= n; ++ i) {
for(int j = 1; j <= n; ++ j) a[i][j] = min( a[i][u] + a[u][j], a[i][j] );
}
}
res = a[C][D];
for(int i = 1; i <= n; ++ i) {
for(int j = 1; j <= n; ++ j) {
if( a[A][i] + a[i][j] + a[j][B] == a[A][B] ) {
res= min( res, a[C][i] + a[j][D] );
}
}
}
swap(A,B);
for(int i = 1; i <= n; ++ i) {
for(int j = 1; j <= n; ++ j) {
if( a[A][i] + a[i][j] + a[j][B] == a[A][B] ) {
res= min( res, a[C][i] + a[j][D] );
}
}
}
cout << res;
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... |