Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1e5;
  6. int n,m;
  7. int ans;
  8. vector<int>graph[N];
  9. bool w[N];
  10.  
  11. void dfs (int v, int pr, int k){
  12.     if (k>m){
  13.         return;
  14.     }
  15.     int ok=1;
  16.     for (auto to : graph[v]){
  17.         if (to!=pr){
  18.             ok=0;
  19.             dfs(to,v,k*w[to]+w[to]);
  20.         }
  21.     }
  22.     ans+=ok;
  23. }
  24.  
  25. int main (){
  26.     ios_base::sync_with_stdio(false);
  27.     cin.tie(nullptr);
  28.     cout.tie(nullptr);
  29.     cin >> n >> m;
  30.     for (int i=0; i<n; ++i){
  31.         int t; cin >> t;
  32.         w[i]=t;
  33.     }
  34.     for (int i=0; i<n-1; ++i){
  35.         int v,u; cin >> v >> u;
  36.         --v;
  37.         --u;
  38.         graph[v].push_back(u);
  39.         graph[u].push_back(v);
  40.     }
  41.     dfs(0,-1,w[0]);
  42.     cout << ans;
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement