Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector <int> x[100500];
- bool pr[100500];
- int q, b, n, m, ans, a[100500];
- int dfs(int v, int cnt){
- pr[v] = 1;
- if(v != 1 && a[v] != 1){
- ans++;
- }
- if(a[v] == 1){
- cnt++;
- }
- for(int i = 0; i < x[v].size(); i++){
- int d = cnt;
- if(!pr[x[v][i]] && d <= m){
- cout << v << " " << x[v][i] << endl;
- d++;
- dfs(x[v][i], d);
- }
- }
- }
- int main(){
- cin >> n >> m;
- for(int i = 0; i < n; i++){
- cin >> a[i];
- }
- for(int i = 0; i < n - 1; i++){
- cin >> q >> b;
- x[q].push_back(b);
- x[b].push_back(q);
- }
- dfs(1, 0);
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement