제출 #545741

#제출 시각아이디문제언어결과실행 시간메모리
545741JomnoiCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
360 ms20176 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int N = 1e5 + 10; const long long INF = 1e18 + 7; vector <pair <int, int>> adj[N]; int n; long long ans; long long dist[4][N], dist2[N]; bool visited[4][N], visited2[N]; void Dijkstra(int id, int s) { fill(dist[id], dist[id] + n + 1, INF); priority_queue <pair <long long, int>> pq; pq.emplace(0, s); dist[id][s] = 0; while(!pq.empty()) { int u = pq.top().second; pq.pop(); if(visited[id][u] == true) { continue; } visited[id][u] = true; for(auto [v, w] : adj[u]) { if(visited[id][v] == false and dist[id][u] + w < dist[id][v]) { dist[id][v] = dist[id][u] + w; pq.emplace(-dist[id][v], v); } } } } void dfs(int id, int u) { dist2[u] = dist[3][u]; visited2[u] = true; for(auto [v, w] : adj[u]) { if(dist[id ^ 1][v] + w == dist[id ^ 1][u]) { if(visited2[v] == false) { dfs(id, v); } dist2[u] = min(dist2[u], dist2[v]); } } ans = min(ans, dist2[u] + dist[2][u]); } int main() { cin.tie(0)->sync_with_stdio(0); int m, S, T, U, V; cin >> n >> m >> S >> T >> U >> V; while(m--) { int a, b, c; cin >> a >> b >> c; adj[a].emplace_back(b, c); adj[b].emplace_back(a, c); } Dijkstra(0, S); Dijkstra(1, T); Dijkstra(2, U); Dijkstra(3, V); ans = dist[2][V]; dfs(0, S); fill(visited2, visited2 + n + 1, false); dfs(1, T); cout << ans; 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...