Submission #123255

#TimeUsernameProblemLanguageResultExecution timeMemory
123255ioilolcomPaprike (COI18_paprike)C++14
24 / 100
66 ms17676 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" typedef long long int ll; const int N=1e5+7; int n,k; int ans[N]; int cnt=0; bool cmp(const int &a,const int &b){ return ans[a]>ans[b]; } vector<int> adj[N]; void dfs(int u,int p){ if(p!=0) { adj[u].erase(find(adj[u].begin(),adj[u].end(),p)); } for(int v:adj[u]) { dfs(v,u); ans[u]+=ans[v]; } sort(adj[u].begin(),adj[u].end(),cmp); for(int a:adj[u]) { if(ans[u]>k) { ans[u]-=ans[a]; cnt++; } else{ break; } } } int main() { ios_base:: sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int i=1; i<=n; i++) { cin>>ans[i]; } for(int i=1; i<n; i++) { int u,v; cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1,0); cout<<cnt<<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...