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;
void solve() {
int n, m;
cin >> n >> m;
int s, t;
cin >> s >> t;
int u, v;
cin >> u >> v;
s--, t--, u--, v--;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
int from, to, cost;
cin >> from >> to >> cost;
from--, to--;
g[from].push_back({to, cost});
g[to].push_back({from, cost});
}
auto djikstra = [&](int s) {
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
greater<>>
pq;
vector<long long> d(n, LLONG_MAX);
d[s] = 0;
pq.push({0, s});
while (!pq.empty()) {
auto [d_v, from] = pq.top();
pq.pop();
if (d_v != d[from]) continue;
for (auto [to, cost] : g[from]) {
if (d[to] > d[from] + cost) {
d[to] = d[from] + cost;
pq.push({d[to], to});
}
}
}
return d;
};
auto a = djikstra(s);
auto b = djikstra(t);
auto c = djikstra(v);
long long ans = LLONG_MAX, mind = a[t];
for (int i = 0; i < n; i++) {
if (a[i] + b[i] == mind) ans = min(ans, c[i]);
}
cout << ans;
}
int main() {
cin.tie(0)->sync_with_stdio(false);
int tt = 1;
// cin >> tt;
while (tt--) {
solve();
}
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... |