Submission #753398

#TimeUsernameProblemLanguageResultExecution timeMemory
753398JomnoiCyberland (APIO23_cyberland)C++17
15 / 100
3058 ms24244 KiB
#include <bits/stdc++.h> #include "cyberland.h" using namespace std; const int MAX_N = 1e5 + 5; const int MAX_K = 35; const long long INF = 1e18 + 7; vector <pair <int, int>> graph[MAX_N]; double dist[MAX_N][MAX_K]; bool visited[MAX_N][MAX_K]; 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++) { graph[i].clear(); for (int k = 0; k <= K; k++) { dist[i][k] = INF; visited[i][k] = false; } } for (int i = 0; i < M; i++) { graph[x[i]].emplace_back(y[i], c[i]); graph[y[i]].emplace_back(x[i], c[i]); } priority_queue <tuple <double, int, int>> pq; pq.emplace(0, 0, 0); dist[0][0] = 0; while (!pq.empty()) { auto [d, k, u] = pq.top(); pq.pop(); if (visited[u][k] == true) continue; visited[u][k] = true; for (auto [v, c] : graph[u]) { if (arr[v] == 0 and visited[v][k] == false and 0 < dist[v][k]) { dist[v][k] = 0; pq.emplace(0, k, v); } else if (arr[v] == 1 and visited[v][k] == false and dist[u][k] + c < dist[v][k]) { dist[v][k] = dist[u][k] + c; pq.emplace(-dist[v][k], k, v); } else if (arr[v] == 2 and k < K and visited[v][k + 1] == false and (dist[u][k] + c) / 2 < dist[v][k + 1]) { dist[v][k + 1] = (dist[u][k] + c) / 2; pq.emplace(-dist[v][k + 1], k + 1, v); } } } double res = INF; for (int k = 0; k <= K; k++) res = min(res, dist[H][k]); if (res == INF) res = -1; return res; }
#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...