이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Commuter Pass
https://oj.uz/problem/view/JOI18_commuter_pass
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
const int N = 1e5;
const LL INF = 1e18;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m; cin >> n >> m;
int s, t, u, v; cin >> s >> t >> u >> v, s--, t--, u--, v--;
static vector<pair<int, int>> g[N];
while (m--) {
int i, j, c; cin >> i >> j >> c, i--, j--;
g[i].push_back({j, c}), g[j].push_back({i, c});
}
auto gen = [&](int s, LL *dt) {
min_pq<pair<LL, int>> q;
fill(dt, dt + n, INF);
q.push({dt[s] = 0, s});
while (!q.empty()) {
auto [d, i] = q.top(); q.pop();
if (d != dt[i]) continue;
for (auto [j, c] : g[i])
if (d + c < dt[j])
q.push({dt[j] = d + c, j});
}
};
static LL ds[N], dt[N];
gen(s, ds), gen(t, dt);
static LL f[N][3];
LL all = ds[t];
for (int i = 0; i < n; i++) f[i][0] = f[i][1] = f[i][2] = INF;
min_pq<tuple<LL, int, int>> q;
q.push({f[u][0] = 0, u, 0});
while (!q.empty()) {
auto [d, i, t] = q.top(); q.pop();
if (d != f[i][t]) continue;
for (auto [j, c] : g[i]) {
if ((t == 0 || t == 1) && (ds[i] + dt[j] + c == all || dt[i] + ds[j] + c == all) && d < f[j][1])
q.push({f[j][1] = d, j, 1});
if (t == 0 && d + c < f[j][0])
q.push({f[j][0] = d + c, j, 0});
if ((t == 1 || t == 2) && d + c < f[j][2])
q.push({f[j][2] = d + c, j, 2});
}
}
cout << min({f[v][0], f[v][1], f[v][2]}) << '\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... |