fork(22) download
  1. #include<iostream>
  2. #include<math.h>
  3. #include<algorithm>
  4. #include<stdio.h>
  5. #include<map>
  6. #include<vector>
  7. #include<set>
  8. #include<iomanip>
  9. #define F first
  10. #define S second
  11. #define P system("PAUSE");
  12. #define H return 0;
  13. #define pb push_back
  14. using namespace std;
  15. const long long A=100000000000000LL,N=228228;
  16.  
  17. vector<long long> a[N];
  18. long long c[N],o,x,y,i,j,n,m;
  19.  
  20. void go(int v,int pr,int k){
  21. if(k>m)return;
  22. int ok=1;
  23. for(int i=0;i<a[v].size();i++)if(a[v][i]!=pr)ok=0,go(a[v][i],v,k*c[a[v][i]]+c[a[v][i]]);
  24. o+=ok;
  25. }
  26.  
  27. int main(){
  28. cin>>n>>m;
  29. for(i=0;i<n;i++)scanf("%d",&c[i]);
  30. for(i=1;i<n;i++)scanf("%d%d",&x,&y),x--,y--,a[x].pb(y),a[y].pb(x);
  31. go(0,-1,c[0]);
  32. cout<<o<<"\n";
  33. }
Success #stdin #stdout 0s 7872KB
stdin
Standard input is empty
stdout
1