Submission #986698

#TimeUsernameProblemLanguageResultExecution timeMemory
986698CSQ31Cyberland (APIO23_cyberland)C++17
97 / 100
479 ms58616 KiB
#include "cyberland.h" #include<bits/stdc++.h> using namespace std; typedef long double ld; ld dist[31][111111]; ld pw[31]; struct node{ int v,k; ld dist = 0; node(int _v,int _k,ld _dist = 0){ v = _v; k = _k; dist = _dist; } }; struct comp { bool operator() (node const &a, node const &b) { return a.dist - b.dist > 1e-10; } }; vector<pair<int,int>>adj[111111]; double solve(int n, int m,int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){ priority_queue<node,vector<node>,comp>pq; for(int j=0;j<n;j++){ adj[j].clear(); for(int i=0;i<=30;i++){ dist[i][j] = 1e15; } } pw[0] = 1; for(int i=1;i<=30;i++)pw[i] = pw[i-1]*2; for(int i=0;i<m;i++){ adj[x[i]].push_back({y[i],c[i]}); adj[y[i]].push_back({x[i],c[i]}); } dist[0][H] = 0; pq.push(node(H,0)); while(!pq.empty()){ node tmp = pq.top(); int v = tmp.v; int k = tmp.k; //cout<<v<<" "<<k<<" "<<tmp.dist<<" "<<dist[k][v]<<'\n'; pq.pop(); if(abs(tmp.dist - dist[k][v]) > 1e-10)continue; if(arr[v] == 0)continue; for(pair<int,int>x : adj[v]){ int u = x.first; if(u == H)continue; ld w = x.second/pw[k]; if(dist[k][u] - dist[k][v] - w > 1e-10){ dist[k][u] = dist[k][v] + w; pq.push(node(u,k,dist[k][u])); } if(arr[u] == 2 && k+1 <= K){ if(dist[k+1][u] - dist[k][v] - w > 1e-10){ dist[k+1][u] = dist[k][v] + w; pq.push(node(u,k+1,dist[k+1][u])); } } } } ld ans = 1e18; for(int i=0;i<=K;i++)ans = min(ans,dist[i][0]); queue<int>q; vector<int>vis(n,0); q.push(0); vis[0] = 1; while(!q.empty()){ int v = q.front(); q.pop(); if(arr[v] == 0){ for(int i=0;i<=K;i++)ans = min(ans,dist[i][v]); } if(v==H)continue; for(pair<int,int>x:adj[v]){ int u = x.first; if(!vis[u]){ q.push(u); vis[u] = 1; } } } if(!vis[H])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...