Submission #958970

#TimeUsernameProblemLanguageResultExecution timeMemory
958970nguyentunglamCyberland (APIO23_cyberland)C++17
21 / 100
86 ms59112 KiB
#include "cyberland.h" #include<bits/stdc++.h> #include <vector> using namespace std; const int N = 1e5 + 10; int a[N]; double d[31][N]; bool vis[31][N]; bool _vis[N]; vector<int> start; vector<pair<int, int> > adj[N]; int n, h, k; #define ii pair<double, int> priority_queue<ii, vector<ii>, greater<ii> > q[31]; void dfs(int u) { _vis[u] = 1; if (a[u] == 0 || u == 0) q[0].push({d[0][u] = 0, u}); for(auto &[v, w] : adj[u]) if (!_vis[v] && v != h) dfs(v); } 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) { n = N; h = H; k = K; for(int i = 0; i < n; i++) adj[i].clear(), _vis[i] = 0; for(int i = 0; i < x.size(); i++) { adj[x[i]].emplace_back(y[i], c[i]); adj[y[i]].emplace_back(x[i], c[i]); } for(int j = 0; j <= k; j++) for(int i = 0; i < n; i++) d[j][i] = 1e16, vis[j][i] = 0; for(int i = 0; i < n; i++) a[i] = arr[i]; dfs(0); for(int j = 0; j <= k; j++) { while (!q[j].empty()) { auto [cost, u] = q[j].top(); q[j].pop(); if (vis[j][u]) continue; if (u == h) continue; vis[j][u] = 1; if (j < k && a[u] == 2) { if (d[j + 1][u] > d[j][u] / 2) q[j + 1].push({d[j + 1][u] = d[j][u] / 2, u}); } for(auto &[v, w] : adj[u]) { if (d[j][v] > d[j][u] + w) q[j].push({d[j][v] = d[j][u] + w, v}); } } } double ans = 1e18; for(int j = 0; j <= k; j++) ans = min(ans, d[j][h]); if (ans > 1e16) ans = -1; return ans; } #ifdef ngu int main() { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); int T; assert(1 == scanf("%d", &T)); while (T--){ int N,M,K,H; assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H)); std::vector<int> x(M); std::vector<int> y(M); std::vector<int> c(M); std::vector<int> arr(N); for (int i=0;i<N;i++) assert(1 == scanf("%d", &arr[i])); for (int i=0;i<M;i++) assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i])); printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr)); } } #endif // ngu

Compilation message (stderr)

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for(int i = 0; i < x.size(); i++) {
      |                  ~~^~~~~~~~~~
#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...