(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #1117784

#TimeUsernameProblemLanguageResultExecution timeMemory
1117784vjudge1Paprike (COI18_paprike)C++17
24 / 100
71 ms8216 KiB
#include "bits/stdc++.h" using ll = long long; using namespace std; const int mxN = 100005; vector<pair<int,int>> aj[mxN]; int cut[mxN]; ll a[mxN]; int flag = 0; ll K; int f; int dfs(int u, int p = 0) { int sm = a[u - 1]; for (auto [v, i] : aj[u]) { if (v ^ p) { int r = dfs(v, u); if (!cut[i]) { sm += r; } } } if (sm > K) { f = 0; } return sm; } int main() { int N; cin >> N >> K; for (int i = 0; i < N; i ++) { cin >> a[i]; } vector<pair<int,int>> eg; for (int i = 0; i < N - 1; i ++) { int X, Y; cin >> X >> Y; eg.emplace_back(X, Y); aj[X].emplace_back(Y, i); aj[Y].emplace_back(X, i); } if (N <= 15) { int mn = INT_MAX; for (int i = 0; i < (1 << (N - 1)); i ++) { for (int j = 0; j < N - 1; j ++) { int bt = (i >> j) & 1; if (bt) { cut[j] = 1; } } f = 1; dfs(1); if (f) { mn = min(mn, __builtin_popcount(i)); } for (int j = 0; j < N - 1; j ++) { cut[j] = 0; } } cout << mn << endl; } else { vector<int> b(N + 1); for (int i = 1; i <= N; i ++) { b[i] = a[i - 1]; } for (int i = 1; i <= N; i ++) { a[i] = b[i]; } int cnt = 0; int j = 0; for (int i = 0; i < N;) { ll sm = 0; for (; i < N && sm + a[i + 1] <= K; i ++) { sm += a[i + 1]; } if (i != N) { cnt ++; } } cout << cnt << endl; } }

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:74:13: warning: unused variable 'j' [-Wunused-variable]
   74 |         int j = 0;
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...