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;
typedef long long int64;
const int maxn = 302;
vector <pair <int, int> > ad [maxn];
int64 d [maxn][maxn];
int main() {
int n,m, s1, t1, s2, t2;
cin >> n >> m >> s1 >> t1 >> s2 >> t2;
for (int i = 0; i < maxn; i++) for (int j = 0; j < maxn; j++) d[i][j] = 1e18;
for (int i = 0; i < m; i++){
int x,y,c;
cin >> x >> y >> c;
ad[x].push_back({y, c});
ad[y].push_back({x, c});
}
auto dijkstra = [&] (int start) {
set <pair <int64, int> > s;
d[start][start] = 0;
s.insert({0, start});
while (!s.empty()) {
int u = s.begin()->second;
s.erase(s.begin());
for (auto &[v, cost]: ad[u]) {
if (d[start][u] + cost < d[start][v]) {
s.erase({d[start][v], v});
d[start][v] = d[start][u] + cost;
s.insert({d[start][v], v});
}
}
}
};
for (int i = 1; i <= n; i++){
dijkstra(i);
}
int64 rs = d[s2][t2];
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
if (min(d[s1][i] + d[t1][j], d[t1][i] + d[s1][j]) + d[i][j] == d[s1][t1]) {
rs = min(rs, min(d[t2][i] + d[s2][j], d[s2][i] + d[t2][j]));
}
}
}
cout << rs << "\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... |