이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pli pair<ll, int>
#define fi first
#define se second
ll MAX = 1e18;
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;
vector<vector<pli>> g (n+1);
for (int i = 0; i < m; i++) {
int a, b;
ll c;
cin >> a >> b >> c;
g[a].push_back({c, b});
g[b].push_back({c, a});
}
vector<ll> lu(n+1, -1), lv(n+1, -1), ls(n+1, -1);
lu[u] = 0; lv[v] = 0; ls[s] = 0;
priority_queue<pli, vector<pli>, greater<pli>> pq;
pq.push({0, u});
while (!pq.empty()) {
pli x = pq.top();
pq.pop();
for (pli y : g[x.se]) {
if (lu[y.se] == -1) {
lu[y.se] = x.fi+y.fi;
pq.push({lu[y.se], y.se});
}
}
}
pq.push({0, v});
while (!pq.empty()) {
pli x = pq.top();
pq.pop();
for (pli y : g[x.se]) {
if (lv[y.se] == -1) {
lv[y.se] = x.fi+y.fi;
pq.push({lv[y.se], y.se});
}
}
}
vector<ll> mu(n+1, MAX), mv(n+1, MAX);
mu[s] = lu[s];
mv[s] = lv[s];
pq.push({0, s});
vector<ll> score(n+1, MAX);
while (!pq.empty()) {
pli x = pq.top();
pq.pop();
score[x.se] = min(score[x.se], min(mv[x.se]+lu[x.se], mu[x.se]+lv[x.se]));
for (pli y : g[x.se]) {
if (ls[y.se] == -1) {
ls[y.se] = x.fi+y.fi;
mu[y.se] = min(mu[x.se], lu[y.se]);
mv[y.se] = min(mv[x.se], lv[y.se]);
score[y.se] = min(score[x.se], min(mu[y.se]+lv[y.se], mv[y.se]+lu[y.se]));
pq.push({ls[y.se], y.se});
}
else if (x.fi+y.fi == ls[y.se]) {
mu[y.se] = min(mu[x.se], mu[y.se]);
mv[y.se] = min(mv[x.se], mv[y.se]);
score[y.se] = min(mu[y.se]+lv[y.se], mv[y.se]+lu[y.se]);
}
}
}
cout << min(score[t], lu[v]) << '\n';
}
# | 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... |