Submission #939959

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