Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e5;
- int n,m;
- int ans;
- vector<int>graph[N];
- bool w[N];
- void dfs (int v, int pr, int k){
- if (k>m){
- return;
- }
- int ok=1;
- for (auto to : graph[v]){
- if (to!=pr){
- ok=0;
- dfs(to,v,k*w[to]+w[to]);
- }
- }
- ans+=ok;
- }
- int main (){
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- cin >> n >> m;
- for (int i=0; i<n; ++i){
- int t; cin >> t;
- w[i]=t;
- }
- for (int i=0; i<n-1; ++i){
- int v,u; cin >> v >> u;
- --v;
- --u;
- graph[v].push_back(u);
- graph[u].push_back(v);
- }
- dfs(0,-1,w[0]);
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement