Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N=1e5+5,
  6. INF=1e9+7;
  7.  
  8. int ans;
  9.  
  10. int n, m;
  11.  
  12. vector<int >a[N];
  13.  
  14. bool usd[N], c[N];
  15.  
  16. void dfs(int v, int sum=0)
  17. {
  18. usd[v]=true;
  19. sum+=c[v];
  20.  
  21. if (sum>m) return;
  22. if (!c[v]) sum=0;
  23.  
  24. if (a[v].size()==1) ans++;
  25.  
  26. for (int i=0; i<a[v].size(); ++i){
  27. int to=a[v][i];
  28. if (!usd[to])
  29. dfs(to, sum);
  30. }
  31. }
  32. main(){
  33. ios_base::sync_with_stdio(0);
  34. cin.tie(0);
  35. cout.tie(0);
  36.  
  37. cin>>n>>m;
  38. for (int i=1; i<=n; ++i){
  39. cin>>c[i];
  40. }
  41. for (int i=1; i<n; ++i){
  42. int x, y;
  43.  
  44. cin>>x>>y;
  45. a[x].push_back(y);
  46. a[y].push_back(x);
  47. }
  48.  
  49. dfs(1);
  50.  
  51. cout<<ans;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement