Submission #851929

#TimeUsernameProblemLanguageResultExecution timeMemory
851929stdfloatCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
262 ms15548 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; vector<pair<int, int>> E[n + 1]; while (m--) { int a, b, c; cin >> a >> b >> c; E[a].push_back({b, c}); E[b].push_back({a, c}); } auto f = [&](int st) -> vector<ll>{ vector<ll> dis(n + 1, LLONG_MAX); dis[st] = 0; priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> q; q.push({0, st}); while (!q.empty()) { int x = q.top().second; q.pop(); for (auto i : E[x]) { if (dis[x] + i.second < dis[i.first]) { dis[i.first] = dis[x] + i.second; q.push({dis[i.first], i.first}); } } } return dis; }; vector<ll> diss = f(s), dist = f(t), disu = f(u), disv = f(v); vector<bool> vis(n + 1); priority_queue<vector<ll>> q; q.push({0, -disu[s] - disv[s], s, disu[s], disv[s]}); while (!q.empty()) { vector<ll> u = q.top(); q.pop(); if (u[2] == t) { return cout << min(disu[v], -u[1]), 0; } if (vis[u[2]]) continue; vis[u[2]] = true; for (auto i : E[u[2]]) { if (diss[u[2]] + i.second == diss[i.first] && diss[i.first] + dist[i.first] == diss[t]) { ll a = min(u[3], disu[i.first]), b = min(u[4], disv[i.first]); q.push({-diss[i.first], - a - b, i.first, a, b}); } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...