제출 #986637

#제출 시각아이디문제언어결과실행 시간메모리
986637CSQ31사이버랜드 (APIO23_cyberland)C++17
8 / 100
3053 ms113232 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 _k,int _v,ld _dist = 0){ v = _v; k = _k; dist = _dist; } }; struct comp { bool operator() (node const &a, node const &b) { return b.dist - a.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]}); } for(int i=0;i<=K;i++){ dist[i][H] = 0; pq.push(node(i,H)); } 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; ld w = x.second; w /= pw[k]; if(dist[k][u] - dist[k][v] - w > 1e-10){ dist[k][u] = dist[k][v] + w; pq.push(node(k,u,dist[k][u])); } if(arr[u] == 2 && k-1 >= 0 ){ if(dist[k-1][u] - dist[k][v] - w > 1e-10){ dist[k-1][u] = dist[k][v] + w; pq.push(node(k-1,u,dist[k-1][u])); } } } } ld ans = dist[0][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)ans = min(ans,dist[0][v]); 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...