Submission #958979

#TimeUsernameProblemLanguageResultExecution timeMemory
958979nguyentunglamCyberland (APIO23_cyberland)C++17
40 / 100
119 ms58972 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; for(auto &[v, w] : adj[u]) { if (j < k && a[u] == 2 && d[j + 1][v] > d[j][u] / 2 + w) q[j + 1].push({d[j + 1][v] = d[j][u] / 2 + w, v}); 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...