제출 #630860

#제출 시각아이디문제언어결과실행 시간메모리
630860Abrar_Al_SamitCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
327 ms21048 KiB
#include<bits/stdc++.h> using namespace std; const int MX = 1e5 + 5; const long long INF = 1e18; vector<pair<int,int>>g[MX]; int n, m, s, t, u, v; vector<long long>d(MX, INF), d2(MX, INF), dist(MX, INF), dist2(MX, INF); vector<long long>dp(MX, INF), dp2(MX, INF); void PlayGround() { cin>>n>>m>>s>>t>>u>>v; for(int i=0; i<m; ++i) { int a, b, c; cin>>a>>b>>c; g[a].emplace_back(b, c); g[b].emplace_back(a, c); } for(int sc : {u, v}) { d[sc] = 0; priority_queue<pair<long long, int>>pq; pq.emplace(0, sc); while(!pq.empty()) { long long cost; int node; tie(cost, node) = pq.top(); pq.pop(); cost = -cost; if(cost!=d[node]) continue; for(auto e : g[node]) if(e.second+cost<d[e.first]) { d[e.first] = cost+e.second; pq.emplace(-d[e.first], e.first); } } swap(d, d2); } for(int sc : {s, t}) { dist[sc] = 0; dp[sc] = d2[sc]; priority_queue<pair<long long, int>>pq; pq.emplace(0, sc); while(!pq.empty()) { long long cost; int node; tie(cost, node) = pq.top(); pq.pop(); cost = -cost; if(cost!=dist[node]) continue; for(auto e : g[node]) { if(e.second+cost<dist[e.first]) { dist[e.first] = cost+e.second; dp[e.first] = min(dp[node], d2[e.first]); pq.emplace(-dist[e.first], e.first); } else if(e.second+cost==dist[e.first]) { dp[e.first] = min(dp[e.first], dp[node]); } } } swap(dp, dp2); swap(dist, dist2); } long long ans = d[v]; for(int i=1; i<=n; ++i) if(dist[i]+dist2[i]==dist[t]) { ans = min(ans, d[i]+min(dp[i], dp2[i])); } cout<<ans<<'\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...