(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 #1117761

#TimeUsernameProblemLanguageResultExecution timeMemory
1117761vjudge1Paprike (COI18_paprike)C++17
11 / 100
4 ms504 KiB
#include "bits/stdc++.h" using namespace std; const int mxN = 20; vector<pair<int,int>> aj[mxN]; int cut[mxN]; int a[mxN]; int flag = 0; int 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); } 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...