Submission #1056474

#TimeUsernameProblemLanguageResultExecution timeMemory
1056474alexddCyberland (APIO23_cyberland)C++17
97 / 100
1929 ms126112 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; typedef long double ld; const long long INF = 1e18; const int MAXK = 64; vector<pair<int,int>> con[100005]; vector<int> tip; ld dist[MAXK+1][100005]; bool visited[100005]; void dfs(int nod, int H) { visited[nod]=1; for(auto [adj,c]:con[nod]) if(!visited[adj] && adj!=H) dfs(adj,H); } 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) { K = min(K, MAXK); for(int i=0;i<N;i++) { con[i].clear(); visited[i]=0; } tip = arr; for(int i=0;i<M;i++) { con[x[i]].push_back({y[i],c[i]}); con[y[i]].push_back({x[i],c[i]}); } dfs(0,H); for(int nr=0;nr<=K;nr++) for(int i=0;i<N;i++) dist[nr][i]=INF; priority_queue<pair<ld,pair<int,int>>> pq; for(int i=0;i<N;i++) { if(i==0 || (visited[i] && tip[i]==0)) { pq.push({0,{0,i}}); dist[0][i]=0; } } while(!pq.empty()) { ld cdist = -pq.top().first; int nod = pq.top().second.second; int cnt = pq.top().second.first; pq.pop(); if(cdist!=dist[cnt][nod] || nod==H) continue; for(auto [adj,c]:con[nod]) { if(tip[adj]==0) { if(dist[cnt][adj]>0) { dist[cnt][adj]=0; pq.push({0,{cnt,adj}}); } } else if(tip[adj]==2) { if(dist[cnt][adj] > cdist + c) { dist[cnt][adj] = cdist + c; pq.push({-dist[cnt][adj],{cnt,adj}}); } if(cnt+1<=K && dist[cnt+1][adj] > (cdist + (ld)c)/2) { dist[cnt+1][adj] = (cdist + (ld)c)/2; pq.push({-dist[cnt+1][adj],{cnt+1,adj}}); } } else { if(dist[cnt][adj] > cdist + c) { dist[cnt][adj] = cdist + c; pq.push({-dist[cnt][adj],{cnt,adj}}); } } } } ld mnm=INF; for(int cnt=0;cnt<=K;cnt++) mnm = min(mnm, dist[cnt][H]); if(mnm==INF) return -1; else return mnm; }
#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...