Submission #575015

#TimeUsernameProblemLanguageResultExecution timeMemory
575015ac2huCommuter Pass (JOI18_commuter_pass)C++14
31 / 100
617 ms43156 KiB
#include <bits/stdc++.h> #ifdef DEBUG #include "../templates/debug.h" #else #define deb(x...) #endif using namespace std; #define int long long signed main() { iostream::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); int n, m;cin >> n >> m; int s, t;cin >> s >> t; --s;--t; int u, v;cin >> u >> v; --u;--v; vector<array<int, 3>> fake_edg(m); vector<vector<pair<int, int>>> fake_adj(n); for(auto &[a, b, c] : fake_edg){ cin >> a >> b >> c; --a;--b; fake_adj[a].push_back({b, c}); fake_adj[b].push_back({a, c}); } set<pair<int,int>> selected_edges;/*{{{*/ priority_queue<pair<int,int>> pq; vector<int> fake_dist(n, 1e18); fake_dist[s] = 0; pq.push({-fake_dist[s], s}); while(!pq.empty()){ auto [dd, x] = pq.top(); dd = -dd; pq.pop(); if(fake_dist[x] != dd)continue; for(auto [e, w] : fake_adj[x]){ if(fake_dist[e] > fake_dist[x] + w){ fake_dist[e] = fake_dist[x] + w; pq.push({-fake_dist[e], e}); } } } vector<vector<int>> temp_adj(n); vector<bool> visited(n, false); queue<int> q; q.push(s); visited[s] = true; while(!q.empty()){ int x = q.front(); q.pop(); for(auto [e, w] : fake_adj[x]){ if(fake_dist[e] == fake_dist[x] + w){ temp_adj[e].push_back(x); if(!visited[e]){ visited[e] = true; q.push(e); } } } } deb(temp_adj); fill(visited.begin(), visited.end(), false); q.push(t); visited[t] = true; while(!q.empty()){ int x = q.front(); q.pop(); for(int e : temp_adj[x]){ selected_edges.insert({min(e, x), max(e, x)}); if(!visited[e]){ visited[e] = true; q.push(e); } } } deb(selected_edges); vector<vector<pair<int,int>>> adj(n); for(auto [a, b, c] : fake_edg){ if(a > b)swap(a, b); if(selected_edges.find({a, b}) != selected_edges.end()){ if(fake_dist[a] < fake_dist[b]){ deb(a, b); adj[a].push_back({b, 0}); adj[b].push_back({a, c}); } else{ deb(b, a); adj[b].push_back({a, 0}); adj[a].push_back({b, c}); } } else{ adj[a].push_back({b, c}); adj[b].push_back({a, c}); } } deb(adj); vector<int> dist(n, 1e18); dist[u] = 0; pq.push({-dist[u], u}); while(!pq.empty()){ auto [dd, x] = pq.top(); pq.pop(); dd = -dd; if(dist[x] != dd)continue; for(auto [e, w] : adj[x]){ if(dist[e] > dist[x] + w){ dist[e] = dist[x] + w; pq.push({-dist[e], e}); } } } int ans = dist[v]; adj.clear(); adj.resize(n); for(auto [a, b, c] : fake_edg){/*{{{*/ if(a > b)swap(a, b); if(selected_edges.find({a, b}) != selected_edges.end()){ if(fake_dist[a] > fake_dist[b]){ deb(a, b); adj[a].push_back({b, 0}); adj[b].push_back({a, c}); } else{ deb(b, a); adj[b].push_back({a, 0}); adj[a].push_back({b, c}); } } else{ adj[a].push_back({b, c}); adj[b].push_back({a, c}); } } fill(dist.begin(), dist.end(), 1e18); dist[u] = 0; pq.push({-dist[u], u}); while(!pq.empty()){ auto [dd, x] = pq.top(); pq.pop(); dd = -dd; if(dist[x] != dd)continue; for(auto [e, w] : adj[x]){ if(dist[e] > dist[x] + w){ dist[e] = dist[x] + w; pq.push({-dist[e], e}); } } } ans = min(ans, dist[v]); cout << ans << "\n";/*}}}*//*}}}*/ }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:17:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   17 |     for(auto &[a, b, c] : fake_edg){
      |               ^
commuter_pass.cpp:29:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |         auto [dd, x] = pq.top();
      |              ^
commuter_pass.cpp:33:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |         for(auto [e, w] : fake_adj[x]){
      |                  ^
commuter_pass.cpp:48:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |         for(auto [e, w] : fake_adj[x]){
      |                  ^
commuter_pass.cpp:75:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   75 |     for(auto [a, b, c] : fake_edg){
      |              ^
commuter_pass.cpp:99:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   99 |         auto [dd, x] = pq.top();
      |              ^
commuter_pass.cpp:103:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  103 |         for(auto [e, w] : adj[x]){
      |                  ^
commuter_pass.cpp:113:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  113 |     for(auto [a, b, c] : fake_edg){/*{{{*/
      |              ^
commuter_pass.cpp:136:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  136 |         auto [dd, x] = pq.top();
      |              ^
commuter_pass.cpp:140:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  140 |         for(auto [e, w] : adj[x]){
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...