Submission #923816

#TimeUsernameProblemLanguageResultExecution timeMemory
923816VMaksimoski008Commuter Pass (JOI18_commuter_pass)C++14
31 / 100
316 ms22524 KiB
#include <bits/stdc++.h> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define int long long using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; const double eps = 1e-9; int32_t main() { int n, m, s, t, U, V; cin >> n >> m >> s >> t >> U >> V; vector<vector<pii> > graph(n+1); for(int i=0; i<m; i++) { int a, b, w; cin >> a >> b >> w; graph[a].push_back({ b, w }); graph[b].push_back({ a, w }); } vector<vector<ll> > dist(3, vector<ll>(n+1, 1e18)); auto dijkstra = [&](int start, int id) { vector<bool> vis(n+1); priority_queue<pll, vector<pll>, greater<pll> > pq; dist[id][start] = 0; pq.push({ 0, start }); while(!pq.empty()) { int u = pq.top().second; pq.pop(); if(vis[u]) continue; vis[u] = 1; for(auto &[v, w] : graph[u]) { if(dist[id][v] > dist[id][u] + w) { dist[id][v] = dist[id][u] + w; pq.push({ dist[id][v], v }); } } } }; dijkstra(s, 0); dijkstra(t, 1); ll SP = dist[0][t]; auto lies_on_sp = [&](int u, int v, int w) { ll cost1 = dist[0][u] + dist[1][v] + w; ll cost2 = dist[1][u] + dist[0][v] + w; return min(cost1, cost2) == SP; }; vector<bool> vis(n+1); priority_queue<pll, vector<pll>, greater<pll> > pq; pq.push({ 0, U }); dist[2][U] = 0; while(!pq.empty()) { int u = pq.top().second; pq.pop(); if(vis[u]) continue; vis[u] = 1; for(auto &[v, w] : graph[u]) { ll cost = (lies_on_sp(u, v, w) ? 0 : w); if(dist[2][v] > dist[2][u] + cost) { dist[2][v] = dist[2][u] + cost; pq.push({ dist[2][v], v }); } } } cout << dist[2][V] << '\n'; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In lambda function:
commuter_pass.cpp:50:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |             for(auto &[v, w] : graph[u]) {
      |                       ^
commuter_pass.cpp: In function 'int32_t main()':
commuter_pass.cpp:82:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   82 |         for(auto &[v, w] : graph[u]) {
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...