Submission #939951

#TimeUsernameProblemLanguageResultExecution timeMemory
939951tamir1Cyberland (APIO23_cyberland)C++17
15 / 100
3014 ms29908 KiB
#include "cyberland.h" #include <bits/stdc++.h> #include <vector> #define ff first #define ss second #define ll long long #define pp pair<double,ll> const double INF=1e18; using namespace std; ll h,i,j; vector<pp> v[200001]; bitset<200005> vis; priority_queue<pair<pair<ll,double>,ll>> q; double dp[200001][31],dist; void dfs(ll a){ if(a==h) return; if(vis[a]) return; vis[a]=1; for(pp l:v[a]){ dfs(l.ss); } } 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) { h=H; dist=INF; dfs(1); for(i=0;i<M;i++){ v[x[i]].push_back({(double)c[i],y[i]}); v[y[i]].push_back({(double)c[i],x[i]}); } q.push({{K,double(0)},0}); for(i=0;i<N;i++){ if(vis[i] && !arr[i]) q.push({{K,double(0)},i}); for(j=0;j<=K;j++){ dp[i][j]=INF; } } while(!q.empty()){ ll a=q.top().ss; ll t=q.top().ff.ff; double d=q.top().ff.ss; q.pop(); if(dp[a][t]<INF) continue; //cout << a << " " << K-t << " " << -d << "\n"; dp[a][t]=-1*d; for(pp l:v[a]){ q.push({{t,d-l.ff},l.ss}); if(arr[a]==2 && t>0){ q.push({{t-1,d/2-l.ff},l.ss}); } } } vis.reset(); for(i=0;i<N;i++){ v[i].clear(); } for(j=0;j<=K;j++){ if(dp[H][j]!=INF) dist=min(dist,dp[H][j]); } if(dist!=INF) return dist; return -1; }
#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...