热身赛就写这一题还读错题意了,以为是求长度为d的最小覆盖集,结果居然是求深度大于d的点数……
/* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> using namespace std; #define pb push_back int n,d; bool vis[100005]; vector<int> org[100005]; int ans; void dfs(int v,int dp) { if(dp>d)return; vis[v]=1; ans++; for(int i=0;i<org[v].size();i++) { int &u=org[v][i]; if(vis[u])continue; dfs(u,dp+1); } return; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&d); int i,a,b; memset(vis,0,sizeof(vis)); for(i=0;i<=n;i++){org[i].clear();} for(i=1;i<n;i++) { scanf("%d%d",&a,&b); org[a].pb(b); org[b].pb(a); } ans=0; dfs(0,0); printf("%d\n",n-ans); } }