# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
955380 | blackslex | Commuter Pass (JOI18_commuter_pass) | C++17 | 208 ms | 22940 KiB |
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;
using ll = long long;
using pii = pair<ll, ll>;
int n, m, s, t, cs, ct, x, y, z;
int main() {
scanf("%d %d %d %d %d %d", &n, &m, &s, &t, &cs, &ct);
vector<vector<pii>> v(n + 5, vector<pii>());
while (m--) scanf("%d %d %d", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z);
vector<ll> d(n + 5, 1e18);
vector<int> par(n + 5);
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.emplace(d[s] = 0, s);
while (!pq.empty()) {
auto [nd, nn] = pq.top(); pq.pop();
for (auto &[tn, td]: v[nn]) if (d[tn] > d[nn] + td) par[tn] = nn, pq.emplace(d[tn] = d[nn] + td, tn);
}
vector<int> u{t};
while (par[u.back()]) u.emplace_back(par[u.back()]);
for (auto &e: u) v[n + 1].emplace_back(e, 0), v[e].emplace_back(n + 1, 0);
vector<ll> d2(n + 5, 1e18);
pq.emplace(d2[cs] = 0, cs);
while (!pq.empty()) {
auto [nd, nn] = pq.top(); pq.pop();
for (auto &[tn, td]: v[nn]) if (d2[tn] > d2[nn] + td) pq.emplace(d2[tn] = d2[nn] + td, tn);
}
printf("%lld", d2[ct]);
}
Compilation message (stderr)
# | 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... |