제출 #719843

#제출 시각아이디문제언어결과실행 시간메모리
719843JuanCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
407 ms26424 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define tii tuple<int, int, int> #define pii pair<int, int> #define ff first #define ss second const int maxn = 1e5 + 5, INF = 0x3f3f3f3f3f3f3f3f; vector<pii> adj[maxn]; vector<int> g[maxn]; vector<tii> edges; int n; vector<int> dijkstra(int ini){ priority_queue<pii, vector<pii>, greater<pii>> pq; vector<int> dist(n+1, INF); dist[ini] = 0; pq.push({0, ini}); while(pq.size()){ auto[d, u] = pq.top(); pq.pop(); if(d > dist[u]) continue; for(int v : g[u]) if(dist[u] < dist[v]){ dist[v] = dist[u]; pq.push({dist[u], v}); } for(auto [v, w] : adj[u]) if(dist[u]+w < dist[v]){ dist[v] = dist[u] + w; pq.push({dist[u]+w, v}); } } return dist; } int32_t main(){ int m; cin >> n >> m; int S, T; cin >> S >> T; int U, V; cin >> U >> V; for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; adj[a].push_back({b, c}); adj[b].push_back({a, c}); edges.push_back({a, b, c}); } vector<int> distS = dijkstra(S), distT = dijkstra(T); int minpath = distS[T]; for(auto[a, b, c] : edges) if(distS[a] < distS[b]){ if(distS[a]+c+distT[b] == minpath) g[a].push_back(b); } vector<int> dist1 = dijkstra(U); int ans = dist1[V]; for(int i = 1; i <= n; i++) g[i].clear(); for(auto[a, b, c] : edges) if(distS[a] < distS[b]){ if(distS[a]+c+distT[b] == minpath) g[b].push_back(a); } vector<int> dist2 = dijkstra(U); ans = min(ans, dist2[V]); 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...