Advertisement
askarulytarlan

Untitled

Mar 29th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector <int> x[100500];
  4. bool pr[100500];
  5. int q, b, n, m, ans, a[100500];
  6. int dfs(int v, int cnt){
  7. pr[v] = 1;
  8. if(v != 1 && a[v] != 1){
  9. ans++;
  10. }
  11. if(a[v] == 1){
  12. cnt++;
  13. }
  14. for(int i = 0; i < x[v].size(); i++){
  15. int d = cnt;
  16. if(!pr[x[v][i]] && d <= m){
  17. cout << v << " " << x[v][i] << endl;
  18. d++;
  19. dfs(x[v][i], d);
  20. }
  21. }
  22. }
  23. int main(){
  24. cin >> n >> m;
  25. for(int i = 0; i < n; i++){
  26. cin >> a[i];
  27. }
  28. for(int i = 0; i < n - 1; i++){
  29. cin >> q >> b;
  30. x[q].push_back(b);
  31. x[b].push_back(q);
  32. }
  33. dfs(1, 0);
  34. cout << ans;
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement