이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |