Submission #782847

#TimeUsernameProblemLanguageResultExecution timeMemory
782847acatmeowmeowCommuter Pass (JOI18_commuter_pass)C++11
15 / 100
913 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long void path(int n, int s, vector<pair<int, long long>> adj[], int dist[]) { dist[s] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({0, s}); while (pq.size()) { int p = pq.top().first, u = pq.top().second; pq.pop(); if (p != dist[u]) continue; for (auto&x : adj[u]) { int v = x.first, c = x.second; if (dist[v] < dist[u] + c) continue; dist[v] = dist[u] + c; pq.push({dist[v], v}); } } } void solve(int n, int s, int t, int u, int v, vector<pair<int, int>> adj[], int f[], int se[]) { int dist[n + 5], mn[n + 5], mn2[n + 5], ans[n + 5]; bool vis[n + 5]; for (int i = 1; i <= n; i++) dist[i] = mn[i] = mn2[i] = ans[i] = 1e18, vis[i] = false; dist[s] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({0, s}); while (pq.size()) { int p = pq.top().first, u = pq.top().second; pq.pop(); //if (p != dist[u]) continue; if (vis[u]) continue; vis[u] = true; mn[u] = min(mn[u], f[u]); mn2[u] = min(mn2[u], se[u]); for (auto&x : adj[u]) { int v = x.first, c = x.second; if (dist[v] + c == dist[u]) { mn[u] = min(mn[u], mn[v]); mn2[u] = min(mn2[u], mn2[v]); ans[u] = min(ans[u], ans[v]); } else if (dist[v] > dist[u] + c) { dist[v] = dist[u] + c; pq.push({dist[v], v}); } } ans[u] = min({ans[u], se[u] + mn[u], f[u] + mn2[u]}); if (u == t) break; } cout << min({ans[t], f[v]}) << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; int s, t; cin >> s >> t; int u, v; cin >> u >> v; vector<pair<int, int>> adj[n + 5]; for (int i = 1;i <= m; i++) { int u, v, c; cin >> u >> v >> c; adj[u].push_back({v, c}); adj[v].push_back({u, c}); } int f[n + 5], se[n + 5]; for (int i = 1;i <= n; i++) f[i] = se[i] = 1e18; path(n, u, adj, f), path(n, v, adj, se); solve(n, s, t, u, v, adj, f, se); return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'void solve(long long int, long long int, long long int, long long int, long long int, std::vector<std::pair<long long int, long long int> >*, long long int*, long long int*)':
commuter_pass.cpp:32:10: warning: unused variable 'p' [-Wunused-variable]
   32 |      int p = pq.top().first, u = pq.top().second;
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...