Submission #655305

#TimeUsernameProblemLanguageResultExecution timeMemory
655305benjaminkleynCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
326 ms31784 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N, M; vector<pair<int,ll>> g[100001]; ll dist[100001]; bool vis[100001]; vector<int> par[100001]; void dijkstra(vector<int> src) { for (int u = 1; u <= N; u++) vis[u] = false, dist[u] = LLONG_MAX; priority_queue<pair<ll, int>> pq; for (int u : src) { dist[u] = 0; pq.push({0LL, u}); } while (!pq.empty()) { int u = pq.top().second; pq.pop(); vis[u] = true; for (auto [v, l] : g[u]) if (dist[v] > dist[u] + l) { par[v] = {u}; dist[v] = dist[u] + l; pq.push({-dist[v], v}); } else if (dist[v] == dist[u] + l) par[v].push_back(u); while (!pq.empty() && vis[pq.top().second]) pq.pop(); } } int main() { int S, T, U, V; cin >> N >> M >> S >> T >> U >> V; for (int i = 0, a, b, c; i < M; i++) { cin >> a >> b >> c; g[a].push_back({b, c}); g[b].push_back({a, c}); } dijkstra({S}); vector<int> path; for (int i = 1; i <= N; i++) { path.push_back(i); for (int x : par[i]) path.push_back(x); } dijkstra(path); cout << dist[U] + dist[S] << '\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...