Submission #976007

#TimeUsernameProblemLanguageResultExecution timeMemory
976007nninCyberland (APIO23_cyberland)C++17
97 / 100
663 ms62372 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; #define pid pair<int,double> #define f first #define s second #define A pair<double, pair<int,int>> vector<pid> adj[100005]; bool reach[100005]; int HH; void dfs(int u) { reach[u] = 1; if(u==HH) return; for(auto [v, w]:adj[u]) { if(!reach[v]) dfs(v); } } double mindis[100005][55]; double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { K = min(K, 50); HH = H; for(int i=0;i<N;i++) { adj[i].clear(); reach[i] = 0; for(int j=0;j<=K;j++) { mindis[i][j] = 1e18; } } for(int i=0;i<M;i++) { adj[x[i]].push_back({y[i], (double)c[i]}); adj[y[i]].push_back({x[i], (double)c[i]}); } dfs(0); if(!reach[H]) return -1; priority_queue<A, vector<A>, greater<A>> pq; pq.push({0, {0, 0}}); mindis[0][0] = 0; for(int i=1;i<N;i++) { if(reach[i] && arr[i]==0) { pq.push({0, {i, 0}}); mindis[i][0] = 0; } } while(!pq.empty()) { double dis = pq.top().f; auto [u, ct] = pq.top().s; pq.pop(); if(mindis[u][ct]!=dis || u==H) continue; for(auto [v, w]:adj[u]) { if(arr[v]>0 && mindis[v][ct]>dis+w) { mindis[v][ct] = dis+w; pq.push({mindis[v][ct], {v, ct}}); } if(arr[v]==2 && ct<K && mindis[v][ct+1]>(dis+w)/2) { mindis[v][ct+1] = (dis+w)/2; pq.push({mindis[v][ct+1], {v, ct+1}}); } } } double ret = 1e18; for(int i=0;i<=K;i++) ret = min(ret, mindis[H][i]); return ret; }
#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...