# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
318464 | Haruto810198 | Paprike (COI18_paprike) | C++17 | 80 ms | 22756 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 int long long
#define double long double
#define vi vector<int>
#define pii pair<int,int>
#define si set<int>
#define mii map<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define pob pop_back
#define pof pop_front
const int INF=2147483647;
const int MOD=1000000007;
const int mod=998244353;
const double eps=1e-12;
int n,k;
int val[100001];
vi edge[100001];
vi subt[100001];
int sum[100001];
int res;
void dfs(int v,int prev){
sum[v]=val[v];
for(int i=0;i<edge[v].size();i++){
if( edge[v][i] != prev ){
dfs( edge[v][i] , v );
sum[v]+=sum[ edge[v][i] ];
subt[v].pb( sum[ edge[v][i] ] );
}
}
sort(subt[v].begin(),subt[v].end());
reverse(subt[v].begin(),subt[v].end());
int ptr=0;
while( sum[v] > k ){
sum[v]-=subt[v][ptr];
ptr++;
res++;
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int v1,v2;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>val[i];
}
for(int i=0;i<n-1;i++){
cin>>v1>>v2;
v1--; v2--;
edge[v1].pb(v2);
edge[v2].pb(v1);
}
dfs(0,-1);
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... |