제출 #1000473

#제출 시각아이디문제언어결과실행 시간메모리
1000473IcelastCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
320 ms54004 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; vector<ll> dijkstra(int s, vector<vector<pair<ll, ll>>> &adj){ int n = adj.size(); vector<ll> dist(n+1, INF); dist[s] = 0; vector<bool> vis(n+1, false); priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq; pq.push({0, s}); while(!pq.empty()){ ll d_u = pq.top().first; int u = pq.top().second; pq.pop(); if(vis[u]){ continue; } vis[u] = true; for(auto it : adj[u]){ int v = it.first; ll w = it.second; if(vis[v]) continue; dist[v] = min(dist[v], d_u+w); pq.push({dist[v], v}); } } return dist; } void solve(){ int n, m; cin >> n >> m; int S, T, U, V; cin >> S >> T; cin >> U >> V; vector<vector<pair<ll, ll>>> adj(n+1), adj1, adj2; for(int i = 1; i <= m; i++){ int u, v, w; cin >> u >> v >> w; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } adj1 = adj; adj2 = adj; vector<ll> ds = dijkstra(S, adj), dt = dijkstra(T, adj); for(int u = 1; u <= n; u++){ if(ds[u]+dt[u] != ds[T]) continue; for(auto it : adj[u]){ int v = it.first; ll w = it.second; if(ds[v]+dt[v] != ds[T]) continue; if(ds[u]+w == ds[v]){ adj1[u].push_back({v, 0}); } if(dt[u]+w == dt[v]){ adj2[u].push_back({v, 0}); } } } vector<ll> du1 = dijkstra(U, adj1), du2 = dijkstra(U, adj2), dv = dijkstra(V, adj); ll ans = INF; ans = min(du1[V], du2[V]); cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("main.inp", "r", stdin); //freopen("main.out", "w", stdout); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...