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 ll long long
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m, s, t, u, v;
cin >> n >> m >> s >> t >> u >> v, s--, t--, u--, v--;
ll adj[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
adj[i][j] = 1e18;
}
}
for (int i = 0; i < n; i++) {
adj[i][i] = 0;
}
while (m--) {
int x, y, w;
cin >> x >> y >> w;
x--, y--;
adj[x][y] = adj[y][x] = w;
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
}
}
}
ll ans = adj[u][v];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (adj[s][t] == adj[s][i] + adj[i][j] + adj[j][t]) {
ans = min({ans, adj[u][i] + adj[j][v], adj[v][i] + adj[j][u]});
}
}
}
cout << 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... |