Submission #1047702

#TimeUsernameProblemLanguageResultExecution timeMemory
1047702inkvizytorCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
136 ms25236 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pli pair<ll, int> #define fi first #define se second ll MAX = 1e18; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; vector<vector<pli>> g (n+1); for (int i = 0; i < m; i++) { int a, b; ll c; cin >> a >> b >> c; g[a].push_back({c, b}); g[b].push_back({c, a}); } vector<ll> lu(n+1, -1), lv(n+1, -1), ls(n+1, -1); lu[u] = 0; lv[v] = 0; ls[s] = 0; priority_queue<pli, vector<pli>, greater<pli>> pq; pq.push({0, u}); while (!pq.empty()) { pli x = pq.top(); pq.pop(); for (pli y : g[x.se]) { if (lu[y.se] == -1) { lu[y.se] = x.fi+y.fi; pq.push({lu[y.se], y.se}); } } } pq.push({0, v}); while (!pq.empty()) { pli x = pq.top(); pq.pop(); for (pli y : g[x.se]) { if (lv[y.se] == -1) { lv[y.se] = x.fi+y.fi; pq.push({lv[y.se], y.se}); } } } pq.push({0, s}); while (!pq.empty()) { pli x = pq.top(); pq.pop(); for (pli y : g[x.se]) { if (ls[y.se] == -1) { ls[y.se] = x.fi+y.fi; pq.push({ls[y.se], y.se}); } } } vector<vector<int>> G (n+1); vector<int> topo (1, s), k (n+1, 0); for (int i = 1; i < n+1; i++) { for (pli j : g[i]) { if (ls[i]+j.fi == ls[j.se]) G[i].push_back(j.se), k[j.se]++; } } queue<int> q; q.push(s); while (!q.empty()) { int x = q.front(); q.pop(); for (int i : G[x]) { k[i]--; if (!k[i]) topo.push_back(i), q.push(i); } } vector<ll> mu(n+1, MAX), mv(n+1, MAX); mu[s] = lu[s]; mv[s] = lv[s]; vector<ll> score(n+1, MAX); score[s] = mu[s]+mv[s]; for (int i : topo) { score[i] = min ({score[i], mu[i]+lv[i], mv[i]+lu[i]}); for (int x : G[i]) { score[x] = min(score[i], score[x]); mu[x] = min({mu[x], mu[i], lu[x]}); mv[x] = min({mv[x], mv[i], lv[x]}); } } cout << min(score[t], lu[v]) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...