Submission #301822

#TimeUsernameProblemLanguageResultExecution timeMemory
301822pit4hCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
703 ms53848 KiB
#include<bits/stdc++.h> #define st first #define nd second #define mp make_pair #define pb push_back #ifndef LOCAL #define cerr if(0)cerr #endif using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; const ll INF = 1e16+1; void dijkstra(int s, vector<vector<pii>>& g, vector<ll>& d) { int n = g.size()-1; vector<bool> vis(n+1); priority_queue<pair<ll, int>> Q; d[s] = 0; Q.push({d[s], s}); while(Q.size()) { int cur = Q.top().nd; Q.pop(); if(vis[cur]) continue; vis[cur] = 1; for(auto nxt: g[cur]) { if(!vis[nxt.st] && d[nxt.st] > d[cur] + nxt.nd) { d[nxt.st] = d[cur] + nxt.nd; Q.push({-d[nxt.st], nxt.st}); } } } } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n, m; cin>>n>>m; int s, t; cin>>s>>t; int u, v; cin>>u>>v; vector<vector<pii>> g(n+1); for(int i=0; i<m; ++i) { int a, b, c; cin>>a>>b>>c; g[a].push_back({b, c}); g[b].push_back({a, c}); } vector<ll> d_s(n+1, INF), d_t(n+1, INF); dijkstra(s, g, d_s); dijkstra(t, g, d_t); auto G = g; for(int i=n+1; i<=3*n; ++i) { G.push_back({}); } for(int i=1; i<=n; ++i) { for(auto edge: g[i]) { int j = edge.st, w = edge.nd; G[i+2*n].push_back({j+2*n, w}); if(d_s[i] + w + d_t[j] == d_s[t]) { G[i+n].push_back({j+n, 0}); } else { G[i+n].push_back({j+2*n, w}); } } } for(int i=1; i<=n; ++i) { G[i].push_back({i+n, 0}); G[i+n].push_back({i+2*n, 0}); } vector<ll> d(3*n+1, INF); auto D = d; dijkstra(u, G, d); dijkstra(v, G, D); cout<<min(d[v+2*n], D[u+2*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...