Submission #41072

#TimeUsernameProblemLanguageResultExecution timeMemory
41072zscoderCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
543 ms21668 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<int> vi; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set<int>::iterator sit; typedef map<int,int>::iterator mit; typedef vector<int>::iterator vit; vector<ii> adj[111111]; int n,m; vector<ll> dijkstra(int s) { priority_queue<ii,vector<ii>,greater<ii> > pq; vector<ll> d(n, ll(1e18)); pq.push(mp(0,s)); d[s] = 0; while(!pq.empty()) { ll dist=pq.top().fi; int u=pq.top().se; pq.pop(); for(ii x:adj[u]) { ll d2 = dist + x.se; if(d[x.fi] > d2) { d[x.fi] = d2; pq.push(mp(d2, x.fi)); } } } return d; } ll dp[111111]; ll dp2[111111]; ll dist[111111]; ll dist2[111111]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; int s,e,s2,e2; cin>>s>>e>>s2>>e2; s--; e--; s2--; e2--; for(int i=0;i<m;i++) { int u,v,c; cin>>u>>v>>c; u--; v--; adj[u].pb(mp(v,c)); adj[v].pb(mp(u,c)); } vector<ll> d1 = dijkstra(s2); vector<ll> d2 = dijkstra(e2); ll ans = d1[e2]; priority_queue<ii,vector<ii>,greater<ii> > pq; for(int i=0;i<n;i++) dist[i]=dist2[i]=dp[i]=dp2[i]=ll(1e18); dist[s] = 0; dp[s] = d2[s]; pq.push(mp(0,s)); while(!pq.empty()) { ll d=pq.top().fi; int u=pq.top().se; pq.pop(); ll pre = dp[u]; for(ii x:adj[u]) { ll dt = d + x.se; int v = x.fi; if(dist[v] > dt) { dp[v] = min(pre, d2[v]); dist[v] = dt; pq.push(mp(dt,v)); } else if(dist[v] == dt) { dp[v] = min(dp[v], min(pre, d2[v])); } } } dist2[e] = 0; dp2[e] = d2[e]; pq.push(mp(0,e)); while(!pq.empty()) { ll d=pq.top().fi; int u=pq.top().se; pq.pop(); ll pre = dp2[u]; for(ii x:adj[u]) { ll dt = d + x.se; int v = x.fi; if(dist2[v] > dt) { dp2[v] = min(pre, d2[v]); dist2[v] = dt; pq.push(mp(dt,v)); } else if(dist2[v] == dt) { dp2[v] = min(dp2[v], min(pre, d2[v])); } } } ll shortestori = dist[e]; for(int i=0;i<n;i++) { if(dist[i]+dist2[i]==shortestori) { ans = min(ans, min(dp[i], dp2[i]) + d1[i]); } } cout<<ans<<'\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...