forked from apaarkamal/competitive_september_2k19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chipped_tree.cpp
60 lines (53 loc) · 1.39 KB
/
chipped_tree.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
const int N = 500005;
vector<int> gr[N];
int dp[N];
int dfs(int cur, int par, int d) {
dp[cur] = 0;
for (auto x : gr[cur]) if (x != par) {
dfs(x, cur, d + 1);
dp[cur] = max(dp[cur], dp[x]);
}
dp[cur]++ ;
}
int32_t main()
{
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t; cin >> t; while (t--)
{
int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
cin >> n >> k;
m = n - 1;
for (i = 0; i <= n; i++) {
gr[i].clear();
dp[i] = 0;
}
for (i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
gr[x].pb(y);
gr[y].pb(x);
}
dfs(1, -1, 0);
for (i = 1; i <= n; i++) {
ans += (dp[i] <= k);
}
cout << ans << '\n';
}
}