0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 19:12:02 +00:00
OI-codes/Luogu/P5908/P5908.cpp

35 lines
608 B
C++
Raw Normal View History

2020-11-05 00:12:33 +00:00
#include <bits/stdc++.h>
using namespace std;
2021-11-19 09:01:13 +00:00
int n, a, b, d, ans;
2020-11-05 00:12:33 +00:00
vector<int> g[100005];
2021-11-19 09:01:13 +00:00
bool vis[100005];
2020-11-05 00:12:33 +00:00
void dfs(int now, int dis) {
vis[now] = true;
if (dis == d) {
return;
}
for (int i = 0; i < g[now].size(); i++) {
if (!vis[g[now][i]]) {
ans++;
dfs(g[now][i], dis + 1);
}
}
return;
}
int main() {
memset(vis, 0x00, sizeof(vis));
cin >> n >> d;
for (int i = 1; i < n; i++) {
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1, 0);
cout << ans << endl;
return 0;
}