Submission #1117616

#TimeUsernameProblemLanguageResultExecution timeMemory
1117616vjudge1Paprike (COI18_paprike)C++17
13 / 100
32 ms6796 KiB
#include<bits/stdc++.h> using namespace std; vector<int>g[100001]; bool vis[100001]; long long val[100001]; int ans=0; long long k,sum; void dfs(int node) { sum+=val[node]; if(sum<=k) { vis[node]=1; for(int go:g[node]) if(!vis[go]) dfs(go); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n>>k; for(int i=1;i<=n;i++) cin>>val[i]; for(int i=0;i<n-1;i++) { int a,b; cin>>a>>b; g[a].push_back(b); g[b].push_back(a); } for(int i=1;i<=n;i++) { if(vis[i]==0) { ans++; dfs(i); sum=0; } } cout<<ans-1; 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...