Submission #1034626

#TimeUsernameProblemLanguageResultExecution timeMemory
1034626XXBabaProBerkayCyberland (APIO23_cyberland)C++17
0 / 100
891 ms2097152 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second using ll = long long; const double INF = 1e16 + 7; vector<vector<pair<int, double>>> adj; vector<bool> vis; void dfs(int k, int& H) { if (k == H || vis[k]) return; vis[k] = 1; for (auto i : adj[k]) dfs(i.F, H); } double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { adj.resize(N); vis.resize(N); 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, H); vector<vector<double>> dist(K + 1, vector<double>(N, INF)); for (int i = 0; i < N; i++) if (arr[i] == 0 && vis[i]) for (int j = 0; j <= K; j++) dist[j][i] = 0; for (int i = 0; i <= K; i++) { priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> PQ; dist[i][0] = 0; for (int j = 0; j < N; j++) if (dist[i][j] == 0) PQ.emplace(0, j); while (!PQ.empty()) { int u; double d; tie(d, u) = PQ.top(); PQ.pop(); if (d != dist[i][u] || u == H) continue; for (auto k : adj[u]) { int v; double w; tie(v, w) = k; bool flag = false; if (dist[i][v] > dist[i][u] + w) { dist[i][v] = dist[i][u] + w; flag = 1; } if (i > 0 && arr[v] == 2 && dist[i][v] > (dist[i - 1][u] + w) / 2.0) { dist[i][v] = min(dist[i][u] + w, (dist[i - 1][u] + w) / 2.0); flag = 1; } if (flag) PQ.emplace(dist[i][v], v); } } } return (dist[K][H] == INF ? -1 : dist[K][H]); }
#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...