Submission #937664

#TimeUsernameProblemLanguageResultExecution timeMemory
937664BaytoroCyberland (APIO23_cyberland)C++17
97 / 100
1976 ms95944 KiB
#include "cyberland.h" #include <bits/stdc++.h> //#include "stub.cpp" using namespace std; #define ll long long //#define int ll #define pb push_back #define tt pair<long double,pair<int,int>> #define fr first #define sc second.first #define tr second.second const ll N1=1e5+5,INF=1e18; long double dist[N1][33]; vector<pair<int,int>> g[N1]; int a[N1]; int used[N1]; void djks(int x, int h, int n){ priority_queue<tt,vector<tt>,greater<tt>> pq; for(int i=0;i<n;i++){ if(used[i] && (i==0 || a[i]==0)){ pq.push({0,{i,0}}); dist[i][0]=0; } } while(!pq.empty()){ tt tmp=pq.top(); pq.pop(); int cur=tmp.sc,t=tmp.tr; if(cur==h) continue; if(abs(dist[cur][t]-tmp.fr)>1e-9) continue; for(auto it: g[cur]){ if(dist[it.first][t]>dist[cur][t]+it.second){ dist[it.first][t]=dist[cur][t]+it.second; pq.push({dist[it.first][t],{it.first,t}}); } if(t==30) continue; if(a[it.first]==2){ if(dist[it.first][t+1]>(dist[cur][t]+it.second)/2){ dist[it.first][t+1]=(dist[cur][t]+it.second)/2; pq.push({dist[it.first][t+1],{it.first,t+1}}); } } } } } void dfs(int x, int h){ used[x]=1; if(x==h) return; for(auto it: g[x]){ if(!used[it.first]) dfs(it.first,h); } } double solve(int n, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { for(int i=0;i<n;i++){ for(int j=0;j<=31;j++) dist[i][j]=INF; g[i].clear(); used[i]=0; } for(int i=0;i<M;i++){ g[x[i]].pb({y[i],c[i]}); g[y[i]].pb({x[i],c[i]}); } for(int i=0;i<n;i++) a[i]=arr[i]; dfs(0,H); if(!used[H]) return -1; djks(0,H,n); long double ans=INF; for(int i=0;i<=K;i++){ ans=min(ans,dist[H][i]); } if(ans==INF) return -1; else 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...