Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5326
Work
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 583 Accepted Submission (s): 392
Problem Description
It's an interesting experience-to-move from ICPC to work, end my college life and start a brand new journey in company.
As is known to all, every stuff in a company have a title, everyone except the boss have a direct leader, and all the Relati Onship forms a tree. If a ' s title is higher than B (A was the direct or indirect leader of B), we call it A manages B.
Now, give you the relation for a company, can-calculate how many people manage k people.
Inputthere is multiple test cases.
Each test case is begins with a integers n and k, n indicates the number of stuff of the company.
Each of the following n-1 lines have both integers a and B, means a is the direct leader of B.
1 <= N <=, 0 <= k < n
1 <= A, B <= N
Outputfor each test case, output the answer as described above.
Sample INPUT7 7 Sample Output2 Source2015 multi-university Training Contest 3 The first line of input: The first number n indicates that there are several Person, the second number m represents the lookup management of two persons. Then there will be n-1 line to express the front of the management behind, the final request is that there are several people are management m personal. See the code.
1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 7 intn,m,map[ the][ the];8 9 intDfsintx)Ten { One intsum=0; A for(intI=1; i<=n;i++) - { - if(map[x][i]==1) the { -sum++; -sum+=DFS (i); - } + } - returnsum; + } A at intMain () - { - intA,b,ans; - while(~SCANF ("%d%d",&n,&m)) - { -ans=0; inmemset (Map,0,sizeof(MAP)); - //memset (ok,0,sizeof (OK)); to for(intI=1; i<=n-1; i++) + { -scanf"%d%d",&a,&b); themap[a][b]=1; * } $ for(intI=1; i<=n;i++)Panax Notoginseng { - if(Dfs (i) = =m) theans++; + } Aprintf ("%d\n", ans); the } + return 0; -}
HDU 5326 Work (Hangzhou Electric Multi-school game third)