제출 #985237

#제출 시각아이디문제언어결과실행 시간메모리
985237thinknoexitCyberland (APIO23_cyberland)C++17
100 / 100
1255 ms92980 KiB
#include "cyberland.h" #include<bits/stdc++.h> using namespace std; using ll = long long; struct A { int v, st; double w; bool operator < (const A& o) const { return w > o.w; } }; vector<A> adj[100100]; priority_queue<A> pq; double dis[101][100100]; double val[101]; bool vis[100100]; int n, m, k, e; void dfs(int v) { vis[v] = 1; if (v == e) return; for (auto& x : adj[v]) { if (!vis[x.v]) dfs(x.v); } } double solve(int NN, int M, int K, int H, vector<int> X, vector<int> Y, vector <int> C, vector<int> a) { n = NN, m = M, k = K, e = H; k = min(k, 96); for (int i = 0;i < m;i++) { adj[X[i]].push_back({ Y[i], 0, (double)C[i] }); adj[Y[i]].push_back({ X[i], 0, (double)C[i] }); } memset(vis, 0, sizeof vis); dfs(0); if (!vis[e]) { for (int i = 0;i < n;i++) adj[i].clear(); return -1; } val[0] = 1; for (int i = 1;i <= k;i++) val[i] = val[i - 1] * 2; for (int i = 0;i <= k;i++) { for (int j = 0;j < n;j++) dis[i][j] = 1e300; } for (int i = 0;i < n;i++) { if (i != 0 && a[i] != 0) continue; if (!vis[i]) continue; pq.push({ i, 0, 0 }); dis[0][i] = 0; } while (!pq.empty()) { auto x = pq.top(); pq.pop(); int v = x.v, st = x.st; if (x.w > dis[st][v]) continue; if (v == e) continue; for (auto& x : adj[v]) { if (dis[st][x.v] > dis[st][v] + x.w * val[st]) { dis[st][x.v] = dis[st][v] + x.w * val[st]; pq.push({ x.v, st, dis[st][x.v] }); } if (a[x.v] == 2 && st < k) { if (dis[st + 1][x.v] > dis[st][v] + x.w * val[st]) { dis[st + 1][x.v] = dis[st][v] + x.w * val[st]; pq.push({ x.v, st + 1, dis[st + 1][x.v] }); } } } } for (int i = 0;i < n;i++) { adj[i].clear(); } double mn = 1e300; for (int j = 0;j <= k;j++) { if (dis[j][e] == 1e300) continue; mn = min(mn, dis[j][e] / val[j]); } return mn; }
#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...