(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.

제출 #44124

#제출 시각아이디문제언어결과실행 시간메모리
44124ShadowLightPaprike (COI18_paprike)C++14
100 / 100
111 ms16204 KiB
#include <bits/stdc++.h> #define ll long long #define TASKNAME "" using namespace std; const int INF = 1e9 + 7; const int MAXN = 1e6 + 7; const double EPS = 1e-8; int n, k; vector <vector <int> > gr; vector <int> w; int res = 0; int dfs(int v, int p) { if (p != -1 && gr[v].size() == 1) { return w[v]; } int sum = w[v]; vector <int> all; for (int u : gr[v]) { if (u == p) continue; all.push_back(dfs(u, v)); } sort(all.begin(), all.end()); for (int i = 0; i < (int) all.size(); i++) { if (sum + all[i] > k) { res += (int) all.size() - i; break; } sum += all[i]; } //cout << res << " " << sum << "\n"; return sum; } int main() { #ifdef MY freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #else //freopen(TASKNAME".in", "r", stdin); //freopen(TASKNAME".out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #endif // MY cin >> n >> k; gr.resize(n); w.resize(n); for (int i = 0; i < n; i++) { cin >> w[i]; } for (int i = 1; i < n; i++) { int v, u; cin >> v >> u; v--, u--; gr[v].push_back(u); gr[u].push_back(v); } dfs(0, -1); res++; cout << res - 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...