제출 #990481

#제출 시각아이디문제언어결과실행 시간메모리
990481OAleksa사이버랜드 (APIO23_cyberland)C++17
0 / 100
2075 ms26328 KiB
#include "cyberland.h" #include <bits/stdc++.h> #define f first #define s second using namespace std; //g++ cyberland.cpp cyberland.h stub.cpp const int N = 1e5 + 69; const long long inf = 1e18; vector<pair<int, int>> g[N]; double dis[N][33]; int vis[N]; void dfs(int v) { if (vis[v]) return; vis[v] = 1; for (auto u : g[v]) dfs(u.f); } double solve(int n, int m, int k, int s, vector<int> x, vector<int> y, vector<int> c, vector<int> a) { //reset for (int i = 0;i < n;i++) { g[i].clear(); vis[i] = 0; } for (int i = 0;i < m;i++) { g[x[i]].push_back({y[i], c[i]}); g[y[i]].push_back({x[i], c[i]}); } dfs(0); if (!vis[s]) return -1; for (int i = 0;i < n;i++) { for (int j = 0;j <= k;j++) dis[i][j] = inf; } dis[s][0] = 0; priority_queue<tuple<double, int, int>> pq; pq.push({0, 0, 0}); for (int i = 1;i < n;i++) { if (a[i] == 0) { dis[i][0] = 0; pq.push({0, i, 0}); } } while (!pq.empty()) { auto x = pq.top(); pq.pop(); int v, j; double d; tie(d, v, j) = x; d = abs(d); for (auto u : g[v]) { if (a[u.f] == 0) continue; if (dis[u.f][j] < d + u.s) { dis[u.f][j] = d + u.s; pq.push({-dis[u.f][j], u.f, j}); } if (a[v] == 2) { if (j < k && dis[u.f][j + 1] < (d + u.s) / 2) { dis[u.f][j] = (d + u.s) / 2; pq.push({-dis[u.f][j + 1], u.f, j + 1}); } } } } double ans = inf; for (int i = 0;i <= k;i++) ans = min(ans, dis[s][i]); return ans; }
#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...