Guest User

Untitled

a guest
Oct 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. /*input
  2. 4 2
  3. 1 2
  4. 1 3
  5. 3 4
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. const int N=5e5 + 100;
  10. const int mod=1e9 + 7;
  11. #define int long long
  12. const int inf=1e18;
  13. #define pii pair<int, int>
  14. #define f first
  15. #define s second
  16. #define mp make_pair
  17. #define FOR(i, n) for(int i=1;i<=n;i++)
  18. #define TRACE(x) cerr << #x << " = " << x << endl
  19. //Trace prints the name of the variable and the value.
  20. int dp[N], n, k;vector<int> adjlist[N];
  21. void dfs(int i, int p)
  22. {
  23. dp[i]=0;
  24. for(auto j:adjlist[i])
  25. {
  26. if(j==p) continue;
  27. dfs(j, i);dp[i]=max(dp[j], dp[i]);
  28. }
  29. dp[i]++;
  30. }
  31. void solve()
  32. {
  33. cin>>n>>k;
  34. for(int i=1;i<=n;i++) adjlist[i].clear();
  35. for(int i=1;i<n;i++)
  36. {
  37. int u, v;cin>>u>>v;adjlist[u].push_back(v);adjlist[v].push_back(u);
  38. }
  39. dfs(1, -1);int ans=0;
  40. for(int i=1;i<=n;i++) ans+=(dp[i]<=k)?1:0;
  41. cout<<ans<<endl;
  42. }
  43. signed main()
  44. {
  45. ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  46. int t;cin>>t;
  47. while(t--) solve();
  48. }
Add Comment
Please, Sign In to add comment