Submission #937638

#TimeUsernameProblemLanguageResultExecution timeMemory
937638BaytoroCyberland (APIO23_cyberland)C++17
68 / 100
2236 ms38240 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<int,pair<int,int>> #define fr first #define sc second.first #define tr second.second const ll N=1e5+5,INF=1e18; double dist[N][33]; vector<pair<int,int>> g[N]; int a[N]; void djks(int x, int h){ dist[x][0]=0; priority_queue<tt,vector<tt>,greater<tt>> pq; pq.push({0,{x,0}}); while(!pq.empty()){ tt tmp=pq.top(); pq.pop(); //double d=tmp.fr; int cur=tmp.sc,t=tmp.tr; if(cur==h) 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]==0){ if(dist[it.first][t+1]>0){ dist[it.first][t+1]=0; pq.push({dist[it.first][t+1],{it.first,t+1}}); } } 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}}); } } } } } 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<=30;j++) dist[i][j]=INF; g[i].clear(); } 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]; djks(0,H); double ans=INF; for(int i=0;i<=K;i++){ //cout<<dist[0][i]<<' '<<dist[1][i]<<' '<<dist[2][i]<<endl; 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...