Submission #824273

#TimeUsernameProblemLanguageResultExecution timeMemory
824273trangtranha28Commuter Pass (JOI18_commuter_pass)C++14
100 / 100
282 ms43888 KiB
#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <stdio.h> #include <climits> #include <vector> #include <queue> #include <map> #include <set> #define int long long using namespace std; const int MAXN = 1e5 + 2; int n, m; int s, t, src, tar; int dis[MAXN] = {0}, dis2[4][MAXN] = {0}; bool vis[MAXN] = {false}; vector <pair <int, int> > adj[MAXN]; vector <int> pp[MAXN], adj2[MAXN], radj[MAXN]; void Dijkstra() { // reset: memset(dis, 0x3f3f3f3f, sizeof(dis)); memset(dis2, 0x3f3f3f3f, sizeof(dis2)); dis[s] = 0; priority_queue <pair <int, int>, vector <pair <int, int> >, greater <pair <int, int> > > pq; pq.push(make_pair(dis[s], s)); while(pq.empty() == false) { pair <int, int> p = pq.top(); pq.pop(); int d = p.first; int v = p.second; if(d != dis[v]) { continue; } for(int i = 0; i < (int)(adj[v].size()); i++) { int u = adj[v][i].first; int w = adj[v][i].second; if(dis[u] > dis[v] + w) { dis[u] = dis[v] + w; pq.push(make_pair(dis[u], u)); pp[u] = {v}; } else if(dis[u] == dis[v] + w) { pp[u].push_back(v); } } } return; } void programme() { // input: cin >> n >> m >> s >> t >> src >> tar; for(int i = 1; i <= m; i++) { int a, b, w; cin >> a >> b >> w; adj[a].push_back(make_pair(b, w)); adj[b].push_back(make_pair(a, w)); } // solve: Dijkstra(); queue <int> q; q.push(t); vis[t] = true; while(q.empty() == false) { int v = q.front(); q.pop(); for(int i = 0; i < (int)(pp[v].size()); i++) { int u = pp[v][i]; adj2[v].push_back(u); radj[u].push_back(v); if(vis[u] == false) { vis[u] = true; q.push(u); } } } // find ans: priority_queue <pair <int, pair <int, int> >, vector <pair <int, pair <int, int> > >, greater <pair <int, pair <int, int> > > > q2; dis2[0][src] = 0; q2.push(make_pair(dis2[0][src], make_pair(0, src))); while(q2.empty() == false) { auto[d, x] = q2.top(); q2.pop(); auto[i, v] = x; if(v == tar) { cout << d << "\n"; return; } if (d != dis2[i][v]) continue; for (auto[u, w]: adj[v]){ int ni = (!i? 0 : 3); if (dis2[ni][u] > dis2[i][v]+w){ q2.push({dis2[ni][u] = dis2[i][v]+w, {ni, u}}); } } if (!i || i == 1){ for (int u: adj2[v]){ if (dis2[1][u] > dis2[i][v]){ q2.push({dis2[1][u] = dis2[i][v], {1, u}}); } } } if (!i || i == 2){ for (int u: radj[v]){ if (dis2[2][u] > dis2[i][v]){ q2.push({dis2[2][u] = dis2[i][v], {2, u}}); } } } } return; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("_mint.inp", "r", stdin); // freopen("_mint.out", "w", stdout); programme(); return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'void programme()':
commuter_pass.cpp:101:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  101 |         auto[d, x] = q2.top();
      |             ^
commuter_pass.cpp:103:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  103 |         auto[i, v] = x;
      |             ^
commuter_pass.cpp:109:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  109 |         for (auto[u, w]: adj[v]){
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...