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

제출 #1118302

#제출 시각아이디문제언어결과실행 시간메모리
1118302vjudge1Paprike (COI18_paprike)C++17
100 / 100
95 ms17596 KiB
#include "bits/stdc++.h" using ll = long long; using namespace std; const int mxN = 100005; vector<int> aj[mxN]; ll a[mxN]; int cnt; ll K; ll dfs(int u, int p = 0) { vector<ll> r; ll sm = a[u]; for (int v : aj[u]) { if (v ^ p) { r.push_back(dfs(v, u)); } } sort(begin(r),end(r)); for (int i : r) { if (sm + i <= K) { sm += i; } else { cnt ++; } } return sm; } int main() { int N; cin >> N >> K; for (int i = 1; i <= N; i ++) { cin >> a[i]; } for (int i = 1; i <= N - 1; i ++) { int X, Y; cin >> X >> Y; aj[X].push_back(Y); aj[Y].push_back(X); } dfs(1, 0); cout << cnt << 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...