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;
const int MAXN = 303;
int n, m, s, t, u, v;
long long d[MAXN][MAXN];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> s >> t >> u >> v;
memset(d, 0x3f, sizeof(d));
for(int i = 1; i <= n; ++i)
d[i][i] = 0;
while(m--) {
int a, b;
long long 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]);
long long ans = d[u][v];
for(int i = 1; i <= n; ++i) {
if(d[s][i] + d[i][t] != d[s][t]) continue;
for(int j = 1; j <= n; ++j) {
if(d[s][i] + d[i][j] + d[j][t] != d[s][t]) continue;
ans = min(ans, d[u][i] + d[j][v]);
ans = min(ans, d[u][j] + d[i][v]);
}
}
cout << ans;
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... |