Submission #416949

#TimeUsernameProblemLanguageResultExecution timeMemory
416949DEQKCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
643 ms15272 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 100100; vector<pair<int, int>> g[N]; void dkstr(int u, vector<ll> &d) { fill(d.begin(), d.end(), 1e15); d[u] = 0; priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> s; s.push({0, u}); while(s.size()) { int v = s.top().second; ll f = s.top().first; s.pop(); if(d[v] != f) continue; for(auto to : g[v]) { if(d[to.first] > d[v] + to.second) { d[to.first] = d[v] + to.second; s.push({d[to.first], to.first}); } } } } int main() { int n, m, s, t, u, v; cin >> n >> m; cin >> s >> t >> u >> v; for(int i = 1; i <= m; i++) { int x, y, w; cin >> x >> y >> w; g[x].emplace_back(y, w); g[y].emplace_back(x, w); } vector<ll> fs(n + 1), ft(n + 1), fu(n + 1), fv(n + 1); dkstr(s, fs); dkstr(t, ft); dkstr(u, fu); dkstr(v, fv); ll ans = fu[v]; for(int it = 0; it < 2; it++) { vector<ll> mn(n + 1, 1e15), f(n + 1, 1e15); priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> d; d.push({0, s}); f[s] = 0; mn[s] = fu[s]; while(d.size()) { int x = d.top().second; ll y = d.top().first; d.pop(); if(f[x] != y) continue; ans = min(ans, mn[x] + fv[x]); for(auto to : g[x]) { if(fs[to.first] + ft[to.first] == fs[t]) { mn[to.first] = min(mn[to.first], min(mn[x], fu[to.first])); if(f[to.first] > to.second + y) { f[to.first] = to.second + y; d.push({f[to.first], to.first}); } } } } swap(fu, fv); } 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...