Submission #772763

#TimeUsernameProblemLanguageResultExecution timeMemory
772763ZeroCoolCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
243 ms25772 KiB
#include <bits/stdc++.h> #define int long long #define debug(u) cerr<<(u == inf ? "inf" : to_string(u))<<endl #define int long long using namespace std; using namespace chrono; const int mxn = 100005; const int inf = 1e18; const int LOG = 17; int n,m,s,t,u,v; vector<pair<int,int> > g[mxn]; void dijk(int x, vector<int>&dis){ priority_queue<pair<int,int> > pq; dis[x] = 0; pq.push({0,x}); while(pq.size()){ int x = (pq.top()).second; pq.pop(); for(auto p : g[x]){ if(dis[p.first] > dis[x] +p.second){ dis[p.first] = dis[x] + p.second; pq.push({-dis[p.first],p.first}); } } } } void solve(int T){ cin >> n >> m >> s >> t >> u >> v; while(m--){ int x, y, w; cin >> x >> y >> w; g[x].push_back({y, w}); g[y].push_back({x, w}); } vector<int> disu(n+1, 1e17), disv(n+1, 1e17), dis(n+1, 1e17), canu(n+1, 1e17), canv(n+1, 1e17); dijk(v, disv); dijk(u, disu); vector<bool> vis(n+1, 0); priority_queue<pair<pair<int,int>,int>, vector<pair<pair<int,int>,int>>, greater<pair<pair<int,int>,int>>> q; q.push({{0, s}, 0}); dis[s] = 0; while(!q.empty()){ int w = q.top().first.first; int x = q.top().first.second, pr = q.top().second; q.pop(); if (w != dis[x]) continue; if (min(disv[x], canv[pr])+min(disu[x], canu[pr]) < canu[x]+canv[x]){ canv[x] = min(disv[x], canv[pr]); canu[x] = min(disu[x], canu[pr]); } if (vis[x]) continue; vis[x] = 1; for (auto i : g[x]){ if (dis[i.first] >= dis[x]+i.second){ dis[i.first] = dis[x]+i.second; q.push({{dis[i.first], i.first}, x}); } } } cout << min(canu[t]+canv[t], disv[u]); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin>>t; for(int i = 1;i<=t;i++){ solve(i); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...