제출 #1113411

#제출 시각아이디문제언어결과실행 시간메모리
1113411Dan4LifeCommuter Pass (JOI18_commuter_pass)C++17
16 / 100
307 ms44772 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(a) (int)a.size() #define all(a) begin(a),end(a) using vi = vector<int>; using ll = long long; using ar2 = array<ll,2>; const int N = (int)2e5+10; const int INF = (int)1e9; const ll LINF = (ll)2e18; vi ts, adj2[N], radj[N]; int n, m, S, T, U, V; ll dis[4][N], ans, D[N], D2[N], vis[N]; vector<ar2> adj[N]; vector<array<ll,3>> edges; void dijkstra(int s, int t){ priority_queue<ar2,vector<ar2>,greater<ar2>> pq; while(sz(pq)) pq.pop(); for(int i = 1; i <= n; i++) dis[t][i]=LINF; dis[t][s] = 0; pq.push({0,s}); while(sz(pq)){ auto [D,a] = pq.top(); pq.pop(); if(D!=dis[t][a]) continue; for(auto [b,w] : adj[a]){ if(dis[t][a]+w<dis[t][b]){ dis[t][b] = dis[t][a]+w; pq.push({dis[t][b],b}); } } } } void dfs(int s,vector<int> adj[]){ vis[s]=1; for(auto u : adj[s]) if(!vis[u]) dfs(u,adj); ts.pb(s); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> S >> T >> U >> V; for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; adj[a].pb({b,c}), adj[b].pb({a,c}); edges.pb({a,b,c}); } dijkstra(S,0); dijkstra(T,1); dijkstra(U,2); dijkstra(V,3); for(int i = 1; i <= n; i++) adj[i].clear(),D[i]=D2[i]=LINF; ans = dis[2][V]; for(auto [a,b,c] : edges){ if(dis[0][a]+c+dis[1][b]==dis[0][T]) adj2[a].pb(b), radj[b].pb(a); swap(a,b); if(dis[0][a]+c+dis[1][b]==dis[0][T]) adj2[a].pb(b), radj[b].pb(a); } dfs(S,adj2); reverse(all(ts)); for(auto u : ts){ D[u] = dis[2][u]; for(auto v : radj[u]) D[u] = min(D[u],D[v]); } ts.clear(); dfs(T,radj); reverse(all(ts)); for(int i = 1; i <= n; i++) D2[i]=dis[3][i]; for(auto u : ts){ for(auto v : adj2[u]) D2[u] = min(D2[u],D2[v]); } for(int i = 1; i <= n; i++) ans = min(ans, D[i]+D2[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...