제출 #983954

#제출 시각아이디문제언어결과실행 시간메모리
983954Halym2007사이버랜드 (APIO23_cyberland)C++17
21 / 100
33 ms10076 KiB
#include <bits/stdc++.h> #include "cyberland.h" using namespace std; #define ff first #define ss second #define pb push_back #define sz size() #define ll long long const int N = 1e5 + 5; vector <pair <int, ll>> v[N]; ll dis[N]; bool vis[N]; void dfs (int x) { vis[x] = 1; for (pair <int, ll> i : v[x]) { if (vis[i.ff]) continue; dfs (i.ff); } } double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { bool subtask = 0; for (int i = 0; i < M; ++i) { v[x[i]].pb ({y[i], (ll)c[i]}); v[y[i]].pb ({x[i], (ll)c[i]}); if (x[i] != i or y[i] != i + 1) { subtask = 1; } } double jogap; if (subtask) { for (int i = 0; i < N; ++i) { dis[i] = 1e18; } vis[H] = 1; dfs (0); vis[H] = 0; priority_queue <pair <ll, int>, vector <pair <ll, int>>, greater <pair <ll, int>>> q; q.push ({0, H}); dis[H] = 0; while (!q.empty()) { int x = q.top().ss; q.pop(); for (pair <int, ll> i : v[x]) { if (dis[i.ff] > dis[x] + i.ss) { dis[i.ff] = dis[x] + i.ss; q.push({dis[i.ff], i.ff}); } } } if (dis[0] != 1e18) { jogap = dis[0]; for (int i = 1; i < N; ++i) { if (!arr[i] and vis[i]) jogap = min (jogap, (double)dis[i]); } } else jogap = -1; } else { int sana = 0; for (int i = H - 1; i >= 0; i--) { if (!arr[i]) break; if (arr[i] == 2 and sana < K) { sana++; vis[i] = 1; } } for (int i = 0; i < H; ++i) { jogap += (double)c[i]; if (!arr[i]) jogap = 0; else if (vis[i]) { jogap /= 2.0; } } } for (int i = 0; i < N; ++i) { v[i].clear(); vis[i] = 0; } return jogap; } //int main() { // freopen ("input.txt", "r", stdin); // 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)); // } //}

컴파일 시 표준 에러 (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:72:10: warning: 'jogap' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |    jogap += (double)c[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...