Submission #749377

#TimeUsernameProblemLanguageResultExecution timeMemory
749377boyliguanhanCyberland (APIO23_cyberland)C++17
100 / 100
2579 ms167760 KiB
#include "cyberland.h" #pragma GCC optimize(2) #define go(a,b,c,d) if(dis[a][b][c]>d) dis[a][b][c] = d, pq.push({b, {d, a, c}}); #include <bits/stdc++.h> using namespace std; double dis[100000][100][2], ans; bool vis[100000]; vector<pair<int, int>> adj[100000]; void dfs(int n, int h) { if(vis[n]) return; vis[n] = 1; if(n==h) return; for(auto i: adj[n]) dfs(i.first, h); } double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { K = min(K, 100); arr[0] = 0, ans = 1e18; for(int i = 0; i < N; i++) for(auto &j: dis[i]) j[0] = j[1] = 1e18; for(int i = 0; i < N; i++) adj[i].clear(), vis[i] = 0; for(int i = 0; i < M; i++) adj[x[i]].push_back({y[i], c[i]}), adj[y[i]].push_back({x[i], c[i]}); dfs(0, H); if(!vis[H]) return -1; priority_queue<pair<int, tuple<double, int, int>>, vector<pair<int, tuple<double, int, int>>>, greater<>> pq; for(int i = 0; i < N; i++) if(vis[i]&&!arr[i]) pq.push({0, {0, i, 0}}); while(pq.size()) { double dist; int node, halves, halved; tie(dist, node, halved) = pq.top().second; halves = pq.top().first, pq.pop(); if(node==H) {ans = min(ans, dist); continue;} if(!halved&&halves<K&&arr[node] == 2) go(node, halves+1, 1, dist/2); for(auto i: adj[node]) go(i.first, halves, 0, dist+i.second); } 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...