제출 #983093

#제출 시각아이디문제언어결과실행 시간메모리
983093abushbandit_사이버랜드 (APIO23_cyberland)C++17
15 / 100
1004 ms2097152 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back 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> a) { vector<vector<pair<int,long double>>> g(n); for(int i = 0;i < m;i++){ g[x[i]].pb({y[i],c[i]}); g[y[i]].pb({x[i],c[i]}); } set<tuple<long double,int,int>> q; q.insert({0,0,k}); long double dis[n][k + 1]; for(int i = 0;i < n;i++){ for(int j = 0;j <= k;j++){ dis[i][j] = 1e18; } } dis[0][k] = 0; while(!q.empty()){ auto [cost,v,nk] = *q.begin();q.erase(*q.begin()); if(dis[v][nk] < cost) continue; for(auto [to,w] : g[v]){ if(a[to] == 0){ if(dis[to][nk] > 0){ dis[to][nk] = 0; q.insert({0,to,nk}); } } else if(a[to] == 1){ if(dis[v][nk] + w < dis[to][nk]){ dis[to][nk] = dis[v][nk] + w; q.insert({dis[to][nk],to,nk}); } } else{ if(nk == 0){ if(dis[v][nk] + w < dis[to][nk]){ dis[to][nk] = dis[v][nk] + w; q.insert({dis[to][nk],to,nk}); } } else{ if((dis[v][nk] + w) / 2 < dis[to][nk]){ dis[to][nk] = (dis[v][nk] + w) / 2; q.insert({dis[to][nk],to,nk}); } } } } } long double ans = 1e18; for(int i = 0;i <= k;i++){ ans = min(ans,dis[h][i]); } if(ans == 1e18) ans = -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...