Submission #978149

#TimeUsernameProblemLanguageResultExecution timeMemory
978149math_rabbit_1028Cyberland (APIO23_cyberland)C++17
44 / 100
3040 ms29756 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; int n, m, k, h; vector<pll> adj[101010]; int ch[101010]; void DFS(int v) { if (v == h) return; if (ch[v]) return; ch[v] = 1; for (int i = 0; i < adj[v].size(); i++) { int u = adj[v][i].first; DFS(u); } } double dis[31][101010]; priority_queue< pair<double, ll> > pq; double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { n = N; m = M; k = K; h = H; for (int i = 0; i < n; i++) adj[i].clear(); for (int i = 0; i < m; i++) { adj[x[i]].push_back({y[i], c[i]}); adj[y[i]].push_back({x[i], c[i]}); } for (int i = 0; i < n; i++) ch[i] = 0; DFS(0); dis[k][0] = 0; pq.push({-dis[k][0], k*n+0}); for (int i = 1; i < n; i++) { if (arr[i] == 0 && ch[i] == 1) { dis[k][i] = 0; pq.push({-dis[k][i], k*n+i}); } else { dis[k][i] = 1e18; } } for (int t = 0; t < k; t++) { for (int i = 0; i < n; i++) dis[t][i] = 1e18; } while (!pq.empty()) { int v = pq.top().second % n, t = pq.top().second / n; double w = -pq.top().first; pq.pop(); if (dis[t][v] < w) continue; for (int i = 0; i < adj[v].size(); i++) { int u = adj[v][i].first; ll ww = adj[v][i].second; if (dis[t][u] > w + ww) { dis[t][u] = w + ww; pq.push({-dis[t][u], t*n+u}); } if (arr[u] != 2) continue; if (t == 0) continue; if (dis[t-1][u] > (w + ww) / 2.0) { dis[t-1][u] = (w + ww) / 2.0; pq.push({-dis[t-1][u], (t-1)*n+u}); } } } double ans = 1e18; for (int t = 0; t <= k; t++) { ans = min(ans, dis[t][h]); } if (ans >= 1e17) return -1; else return ans; }

Compilation message (stderr)

cyberland.cpp: In function 'void DFS(int)':
cyberland.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 0; i < adj[v].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~
cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:60:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for (int i = 0; i < adj[v].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...