# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238671 | Kastanda | Paprike (COI18_paprike) | C++11 | 86 ms | 17656 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Criminal
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, k, Cnt, A[N];
vector < int > Adj[N];
int DFS(int v, int p)
{
vector < int > V;
for (int u : Adj[v])
if (u != p)
V.push_back(DFS(u, v));
sort(V.begin(), V.end());
long long SM = A[v];
for (int a : V)
SM += a;
while (SM > k)
SM -= V.back(), V.pop_back(), Cnt ++;
return (SM);
}
int main()
{
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i ++)
scanf("%d", &A[i]);
for (int i = 1; i < n; i ++)
{
int v, u;
scanf("%d%d", &v, &u);
Adj[v].push_back(u);
Adj[u].push_back(v);
}
DFS(1, 0);
return !printf("%d\n", Cnt);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |