제출 #1129866

#제출 시각아이디문제언어결과실행 시간메모리
1129866julia_08Commuter Pass (JOI18_commuter_pass)C++20
16 / 100
228 ms23440 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MAXN = 2e5 + 10; const int INF = 1e18; vector<pair<int, int>> adj[MAXN]; int marc[MAXN][3], dist[MAXN][3]; int n, m; void dijkstra(int v, int x){ for(int i=1; i<=n; i++){ dist[i][x] = INF; } priority_queue<pair<int, int>> q; dist[v][x] = 0; q.push({0, v}); while(!q.empty()){ auto [d, v] = q.top(); q.pop(); if(marc[v][x]) continue; marc[v][x] = 1; for(auto [u, w] : adj[v]){ if(dist[v][x] + w < dist[u][x]){ dist[u][x] = dist[v][x] + w; q.push({-dist[u][x], u}); } } } } int32_t main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> m; int s, t; cin >> s >> t; int u, v; cin >> u >> v; for(int i=1; i<=m; i++){ int a, b, c; cin >> a >> b >> c; adj[a].push_back({b, c}); adj[b].push_back({a, c}); } // s = u: dijkstra(s, 0); dijkstra(t, 1); dijkstra(v, 2); int min_dist = dist[t][0]; // s -> t int ans = dist[v][0]; for(int i=1; i<=n; i++){ if(dist[i][0] + dist[i][1] == min_dist){ ans = min(ans, dist[i][2]); } } cout << ans << "\n"; 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...