Submission #1292886

#TimeUsernameProblemLanguageResultExecution timeMemory
1292886goulthenCyberland (APIO23_cyberland)C++20
44 / 100
623 ms55144 KiB
#include <bits/stdc++.h> #include "cyberland.h" using namespace std; #define ld long double #define pii pair<ld,int> #define ll long long #define rep(i,a,b) for(int i = a; i <= b; i++) const ll INF = 1e18+10; const int MAXN = 1e5+10; bool mk[MAXN]; void dfs(int u, vector<vector<pii>> &g, int H) { if(mk[u]) return; mk[u] = 1; if (u==H) return; for(auto &[v,w] : g[u]) dfs(v,g,H); } using z = pair<ld, pair<int,int>>; 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) { K=min(K,100); rep(i,0,N-1) mk[i] = 0; vector<vector<ld>> dist(N, vector<ld>(K,INF)); vector<vector<pii>> g(N); rep(i,0,M-1) { g[x[i]].emplace_back(y[i],c[i]); g[y[i]].emplace_back(x[i],c[i]); } dfs(0,g,H); priority_queue<z,vector<z>,greater<z>> pq; dist[0][0] = 0; pq.push({0,{0,0}}); rep(i,1,N-1) if(arr[i]==0 && mk[i]) { pq.push({0,{i,0}}); dist[i][0] = 0; } vector<vector<bool>> vis(N, vector<bool>(K,0LL)); while (!pq.empty()) { auto [d,h] = pq.top();pq.pop(); int u = h.first; int ck = h.second; if(vis[u][ck]) continue; //cout << u << ' ' << d << ' ' << ck << '\n'; vis[u][ck] = 1; for(auto &[v,w] : g[u]) { ld nd = d+w; int cck = ck; if(arr[v] == 2 && cck < K-1) { cck++; nd/=2; } if (nd >= dist[v][cck]) continue; dist[v][cck] = nd; pq.push({dist[v][cck],{v,cck}}); } } if(!mk[H]) return -1; ld ans = INF; rep(i,0,K-1) ans = min(ans,dist[H][i]); if(ans == INF) return -1; 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...