Submission #972631

#TimeUsernameProblemLanguageResultExecution timeMemory
972631TheSahibCyberland (APIO23_cyberland)C++17
0 / 100
56 ms117852 KiB
#include "cyberland.h" #include <bits/stdc++.h> #define ll long long #define pii pair<int, int> using namespace std; const ll oo = 1e18; const int MAX = 1e5 + 5; const int MAXK = 70; const int LOGMAX = 7; struct edge{ int u, c; }; int n, k, f; int A[MAX]; vector<edge> g[MAX]; bool visited[MAX]; vector<int> starts; void dfs(int node){ visited[node] = 1; for(auto& e:g[node]){ if(visited[e.u]) continue; dfs(e.u); } } double dist[MAXK + 1][MAX]; priority_queue<pair<double, int>> st; void dijkstra(){ for (int j = 0; j <= k; j++) { for (int i = 0; i < n; i++) { dist[j][i] = oo; } } for(int a:starts){ dist[k][a] = 0; st.push({0, a << LOGMAX + k}); } while(!st.empty()){ double d = -st.top().first; int node = st.top().second >> LOGMAX; int l = st.top().second - (node << LOGMAX); st.pop(); if(dist[l][node] < d) continue; for(auto& e:g[node]){ double b = d + e.c; if(b < dist[l][e.u]){ dist[l][e.u] = b; st.push({-dist[l][e.u], (e.u << LOGMAX) + (l - 1)}); } if(l == 0 || A[e.u] != 2) continue; if(b / 2 < dist[l - 1][e.u]){ dist[l - 1][e.u] = b / 2; st.push({-dist[l - 1][e.u], (e.u << LOGMAX) + (l - 1)}); } } } } double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { n = N; k = min(MAXK, K); f = H; starts.clear(); for (int i = 0; i < n; i++) { A[i] = arr[i]; g[i].clear(); visited[i] = 0; } for (int i = 0; i < M; i++) { g[x[i]].push_back({y[i], c[i]}); g[y[i]].push_back({x[i], c[i]}); } g[f].clear(); dfs(0); starts.push_back(0); for (int i = 0; i < n; i++) { if(visited[i] && A[i] == 0){ starts.push_back(i); } } dijkstra(); double ans = oo; for(int i = 0; i <= k; ++i){ ans = min(ans, dist[i][f]); } if(ans == oo){ return -1; } else{ return ans; } }

Compilation message (stderr)

cyberland.cpp: In function 'void dijkstra()':
cyberland.cpp:44:33: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   44 |         st.push({0, a << LOGMAX + k});
      |                          ~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...