Submission #794087

#TimeUsernameProblemLanguageResultExecution timeMemory
79408712345678Cyberland (APIO23_cyberland)C++17
0 / 100
3065 ms32824 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; const int nx=1e5+5, kx=31; priority_queue<pair<double, pair<int, double>>, vector<pair<double, pair<int, double>>>, greater<pair<double, pair<int, double>>>> pq; vector<vector<pair<int, int>>> d(nx); double dp[nx][kx], ans=DBL_MAX; double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) { for (int i=0; i<M; i++) d[x[i]].push_back({y[i], c[i]}), d[y[i]].push_back({x[i], c[i]}); for (int i=0; i<N; i++) if (arr[i]==0) pq.push({0, {0, i}}); for (int i=0; i<N; i++) { if (arr[i]!=0) for (int j=0; j<kx; j++) dp[i][j]=DBL_MAX; } dp[0][0]=0; pq.push({0, {0, 0}}); while (!pq.empty()) { auto cw=pq.top().first, cl=pq.top().second.second; auto ck=pq.top().second.first; pq.pop(); //cout<<cw<<' '<<ck<<' '<<cl<<'\n'; if (cl==H) continue; for (auto [v, w]:d[cl]) { if (dp[v][ck]>cw+w) pq.push({cw+w, {ck, v}}), dp[v][ck]=cw+w; if (arr[v]==2&&ck!=K) if (dp[v][ck+1]>(cw+w)/2) pq.push({(cw+w)/2, {ck+1, v}}), dp[v][ck+1]=(cw+w)/2; } } for (int i=0; i<=K; i++) ans=min(ans, dp[H][i]); if (ans==DBL_MAX) return -1; return ans; }
#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...