Submission #874717

#TimeUsernameProblemLanguageResultExecution timeMemory
874717ItamarCyberland (APIO23_cyberland)C++17
0 / 100
213 ms24408 KiB
#include <vector> using namespace std; #define vi vector<int> #define pi pair<int,int> #define x first #define y second #include "cyberland.h" #define pd pair<double,double> #define pdi pair<double,int> #define vd vector<double> #include <vector> #include <queue> void dfs(vector<bool>&vis, int i, int H,vector<vector<pdi>>&fr) { if (i ==H)return; if (vis[i])return; vis[i] = 1; for (pdi p : fr[i]) { dfs(vis, p.y, H, fr); } } 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, 69); vector<vd> dp(N, vd(K + 2,1e15)); vector<vector<pdi>> fr(N); for (int i = 0; i < M; i++) { fr[X[i]].push_back({ c[i],Y[i] }); fr[Y[i]].push_back({ c[i],X[i] }); } priority_queue<pair<int,pdi>> pq; vi fre; vector<bool> vis(N); dfs(vis, 0,H,fr); pq.push({ 0,{0,0} }); for (int i = 0; i < N; i++)if (vis[i] == 1 && arr[i] == 0)pq.push({ 0,{0,i} }); while (!pq.empty()) { pair<int, pdi> q = pq.top(); int s = q.x; pdi p = q.y; pq.pop(); if ((- s) > K)continue; if (dp[p.y][-s] < -p.x)continue; dp[p.y][-s] = -p.x; if (p.y == H)continue; for (pd f : fr[p.y]) { if(arr[p.y]==2)pq.push({ s - 1,{p.x / 2 - f.x,f.y} }); if(f.x-p.x < dp[-s][f.y])pq.push({ s,{p.x - f.x,f.y} }); } } double mini = 1e15; for (int i = 0; i <= K; i++)mini = min(mini, dp[H][i]); if(mini==1e15)return -1; return mini; }
#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...