# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
113096 | IVIosab | Paprike (COI18_paprike) | C++17 | 81 ms | 18040 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.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
int n,m;
int ar[100005];
vector<vector<int>> adj(100005);
int res=0;
int vis[100005];
int dfs(int cur){
vis[cur]=1;
vector<int> v;
for(int i=0;i<adj[cur].size();i++){
if(!vis[adj[cur][i]]) {
v.push_back(dfs(adj[cur][i]));
}
}
sort(v.begin(),v.end());
int ret=ar[cur];
for(int i=0;i<v.size();i++){
if(v[i]+ret>m){
res++;
}
else{
ret+=v[i];
}
}
return ret;
}
int main() {
//freopen("sample-8.in", "r", stdin);
//freopen("output8.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>ar[i];
}
for(int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(0);
cout<<res<<endl;
return 0;
}
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... |