제출 #851917

#제출 시각아이디문제언어결과실행 시간메모리
851917stdfloatCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
278 ms15296 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; pair<ll, ll> y; int n, m, s, t, u, v, a, b, c, x; vector<bool> vis; vector<ll> dis, diss, dist, disu, disv; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m >> s >> t >> u >> v; vector<pair<int, int>> E[n + 1]; while (m--) { cin >> a >> b >> c; E[a].push_back({b, c}); E[b].push_back({a, c}); } auto f = [&](int st) -> vector<ll>{ dis.assign(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()) { 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; }; diss = f(s); dist = f(t); disu = f(u); disv = f(v); ll ans = disu[v]; vis.assign(n + 1, false); priority_queue<pair<ll, pair<int, pair<ll, ll>>>, vector<pair<ll, pair<int, pair<ll, ll>>>>, greater<>> q; q.push({0, {s, {disu[s], disv[s]}}}); while (!q.empty()) { x = q.top().second.first; y = q.top().second.second; q.pop(); if (x == t) { ans = min(ans, y.first + y.second); continue; } if (vis[x]) continue; vis[x] = true; for (auto i : E[x]) { if (diss[x] + i.second == diss[i.first] && diss[i.first] + dist[i.first] == diss[t]) { q.push({diss[i.first], {i.first, {min(y.first, disu[i.first]), min(y.second, disv[i.first])}}}); } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...