Submission #1043905

#TimeUsernameProblemLanguageResultExecution timeMemory
1043905vjudge1Paprike (COI18_paprike)C++17
100 / 100
59 ms19164 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int const N=1e5+5; int const mod=1e9+7; int cut[N],val[N]; vector<int> adj[N]; int n,k; void dfs(int node,int par){ vector<int> v; for(int i:adj[node]){ if(i==par) continue; dfs(i,node); cut[node]+=cut[i]+1; v.push_back(val[i]); } sort(v.begin(), v.end()); for(int i:v) if(i+val[node]<=k){ val[node]+=i; cut[node]--; } } int main(){ cin>>n>>k; for (int i = 1; i <=n; ++i) cin>>val[i]; for (int i = 0; i < n-1; ++i){ int u,v; cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1,0); cout<<cut[1]<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...