Submission #335621

#TimeUsernameProblemLanguageResultExecution timeMemory
335621rynoCommuter Pass (JOI18_commuter_pass)C++14
16 / 100
387 ms20620 KiB
#include <algorithm> #include <iostream> #include <vector> #include <limits> #include <queue> using namespace std; typedef long long ll; ll N, M, S, T, U, V, dist[5][100005]; bool good[100005]; pair<ll, ll> best[100005]; vector<pair<ll, ll>> routes[100005]; priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq; void dk(ll s, ll id) { dist[id][s] = 0; pq.push({ 0, s }); while (!pq.empty()) { auto curr = pq.top(); pq.pop(); if (curr.first > dist[id][curr.second]) continue; for (auto child : routes[curr.second]) { if (child.first + curr.first < dist[id][child.second]) { dist[id][child.second] = child.first + curr.first; pq.push({ dist[id][child.second], child.second }); } } } } pair<ll, ll> updated(ll node, pair<ll, ll> newVal) { return { min(best[node].first, newVal.first), min(best[node].second, newVal.second) }; } ll solve() { ll output = dist[1][S] + dist[2][S]; dist[3][S] = dist[1][S]; pq.push({ 0, S }); while (!pq.empty()) { auto curr = pq.top(); pq.pop(); if (curr.first > dist[3][curr.second]) continue; for (auto child : routes[curr.second]) { if (dist[0][child.second] + child.first == dist[0][curr.second]) { int newD = min(dist[1][child.second], dist[3][curr.second]); if (newD < dist[3][child.second]) { output = min(output, newD + dist[2][child.second]); dist[3][child.second] = newD; pq.push({ newD, child.second }); } } } } return output; } int main() { fill(dist[0], dist[4], numeric_limits<ll>::max()); cin.tie(0); ios::sync_with_stdio(0); cin >> N >> M >> S >> T >> U >> V; ll a, b, c; for (ll i = 0; i < M; ++i) { cin >> a >> b >> c; routes[a].push_back({ c, b }); routes[b].push_back({ c, a }); } // dist[0] = nuke path // dist[1] = distances to U // dist[2] = distances to V // dist[3] = u_x to u + v_x to v (considering dist[1] then dist[2]) dk(T, 0); dk(U, 1); dk(V, 2); cout << solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...