CF580C
说句实话,这道题作为蓝题过于简单了一点
#include<iostream>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
#define fi(i,a,b) for(int i = a; i <= b; ++i)
#define fr(i,a,b) for(int i = a; i >= b; --i)
#define x first
#define y second
#define sz(x) ((int)(x).size())
#define pb push_back
using pii = pair<int,int>;
//#define DEBUG
const int N = 1e5 + 5;
int n,m;
vector<int> vec[N];
int w[N];
bool vis[N];
int ans;
void dfs(int x,int y){
vis[x] = true;
if(y > m) return;
if(sz(vec[x]) == 1 && x != 1) {ans++;return;}
fi(i,0,sz(vec[x]) - 1){
if(vis[vec[x][i]]) continue;
if(w[vec[x][i]]) dfs(vec[x][i],y+1);
else dfs(vec[x][i],0);
}
vis[x] = false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
fi(i,1,n) cin >> w[i];
fi(i,1,n-1) {
int a,b;
cin >> a >> b;
vec[a].pb(b);
vec[b].pb(a);
}
dfs(1,w[1]);
cout << ans << endl;
#ifdef DEBUG
//freopen(D:\in.txt,r,stdin);
#endif
return 0;
}