标签:str mat name tac math oid 模板 printf include
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstring> 5 #include <algorithm> 6 #include <queue> 7 #include <stack> 8 #include <vector> 9 using namespace std; 10 const int N=100050; 11 int n,m,vis[N],d[N],ans; 12 vector<int>G[N]; 13 void clear() 14 { 15 memset(vis,0,sizeof(vis)); 16 memset(d,0,sizeof(d)); 17 ans=0; 18 for(int i=0;i<n;i++) 19 G[i].clear(); 20 } 21 void add(int v,int u) 22 { 23 G[v].push_back(u); 24 G[u].push_back(v); 25 } 26 void dfs(int k) 27 { 28 vis[k]=1; 29 for(int i=0;i<G[k].size();i++) 30 { 31 int v=G[k][i]; 32 if(vis[v]==0) 33 { 34 d[v]=d[k]+1; 35 if(d[v]>m) 36 ans++; 37 dfs(v); 38 } 39 } 40 } 41 int main(int argc, char *argv[]) 42 { 43 int t; 44 scanf("%d",&t); 45 while(t--) 46 { 47 scanf("%d%d",&n,&m); 48 clear(); 49 for(int i=1;i<n;i++) 50 { 51 int u,v; 52 scanf("%d%d",&u,&v); 53 add(u,v); 54 } 55 dfs(0); 56 printf("%d\n",ans); 57 } 58 return 0; 59 }
标签:str mat name tac math oid 模板 printf include
原文地址:https://www.cnblogs.com/huluxin/p/9430773.html