标签:ati accept clear namespace cat class 忘记 got sep
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2799 Accepted Submission(s):
1379
#define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<algorithm> #include<string> #include<set> #include<map> #include<vector> #include<queue> using namespace std; const int N_MAX = 100000+4; int N, D; int num_of_ceng[N_MAX]; vector<int>G[N_MAX]; queue<int>que; int main() { int T; scanf("%d",&T); while (T--) { memset(num_of_ceng, 0, sizeof(num_of_ceng)); scanf("%d%d",&N,&D); for (int i = 0; i < N-1;i++) { int a, b; scanf("%d%d",&a,&b); G[a].push_back(b); G[b].push_back(a);//一定要双向记录,题设只是说a和b相邻,没说谁是父亲谁是儿子 } que.push(0);//将根节点压入队列 int num = 0; while (!que.empty()) { int father = que.front(); que.pop(); for (int i = 0; i < G[father].size(); i++) { if (father<G[father][i]) { num_of_ceng[G[father][i]] = num_of_ceng[father] + 1; int num_ceng = num_of_ceng[G[father][i]]; if (num_ceng > D)num++; que.push(G[father][i]); } } } printf("%d\n", num); for (int i = 0; i < N; i++) {//不要忘记清空,以便下次操作 G[i].clear(); } } return 0; }
标签:ati accept clear namespace cat class 忘记 got sep
原文地址:http://www.cnblogs.com/ZefengYao/p/6668871.html