제출 #983227

#제출 시각아이디문제언어결과실행 시간메모리
983227h_squared사이버랜드 (APIO23_cyberland)C++17
97 / 100
3063 ms182948 KiB
#include "cyberland.h" #include<bits/stdc++.h> #include <cmath> using namespace std; struct node{ int u,k;double cost; }; 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) { vector<vector<pair<int,int>>>adj(N); 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]}); } K=min(K,150); vector<vector<double>>d(N,vector<double>(K+1,1e18)); d[0][0]=0; auto cmp=[](node& a,node &b){return a.cost>b.cost;}; priority_queue<node,vector<node>,decltype(cmp)>pq(cmp); pq.push({0,0,0}); double ans=1e18; while(!pq.empty()){ auto [u,k,cost]=pq.top();pq.pop(); if(d[u][k]<cost)continue; if(u==H){ ans=min(ans,cost); continue; } for(auto [v,w]:adj[u]){ double now=cost+w; if(arr[v]==0){ now=0; if(now<d[v][0]){ d[v][0]=now; pq.push({v,0,now}); } } else{ if(now<d[v][k]){ d[v][k]=now; pq.push({v,k,now}); } if(arr[v]==2 && k<K){ now=now/2; if(now<d[v][k+1]){ d[v][k+1]=now; pq.push({v,k+1,now}); } } } } } if(ans==1e18)return -1; else 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...