Submission #977871

#TimeUsernameProblemLanguageResultExecution timeMemory
977871UnforgettableplCyberland (APIO23_cyberland)C++17
44 / 100
3019 ms64088 KiB
#include <bits/stdc++.h> using namespace std; #define int long long vector<int32_t> powers; vector<vector<pair<int,double>>> adj; priority_queue<pair<int,pair<double,int>>,vector<pair<int,pair<double,int>>>,greater<>> q; vector<bool> visited; void dfs(int x){ if(visited[x])return; visited[x]=true; if(powers[x]==0)q.emplace(0, make_pair(0,x)); for(auto[dest,c]:adj[x])dfs(dest); } double solve(int32_t N, int32_t M, int32_t K, int32_t H, vector<int32_t> x, vector<int32_t> y, vector<int32_t> c, vector<int32_t> arr) { swap(powers,arr); visited = vector<bool>(N); adj = vector<vector<pair<int,double>>>(N); while(!q.empty())q.pop(); powers[0] = 0; visited[H]=true; for(int i=0;i<M;i++){ adj[x[i]].emplace_back(y[i],c[i]); adj[y[i]].emplace_back(x[i],c[i]); } dfs(0); vector<vector<bool>> vis(N,vector<bool>(K+1)); while(!q.empty()){ auto [uses,curr] = q.top();q.pop(); auto [tim,idx] = curr; if(idx==H)return tim; if(vis[idx][uses])continue; vis[idx][uses]=true; for(auto[dest,cost]:adj[idx]){ if(!vis[dest][uses])q.emplace(uses,make_pair(tim+cost,dest)); if(powers[dest]==2 and uses<K and !vis[dest][uses+1])q.emplace(uses+1,make_pair((tim+cost)/double(2),dest)); } } 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...