hdu 5326 Work(杭电多校赛第三场)
来源:互联网 发布:js验证提示信息 编辑:程序博客网 时间:2024/06/05 10:29
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326
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 has a title, everyone except the boss has a direct leader, and all the relationship forms a tree. If A’s title is higher than B(A is the direct or indirect leader of B), we call it A manages B.
Now, give you the relation of a company, can you calculate how many people manage k people.
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 has a title, everyone except the boss has a direct leader, and all the relationship forms a tree. If A’s title is higher than B(A is the direct or indirect leader of B), we call it A manages B.
Now, give you the relation of a company, can you calculate how many people manage k people.
Input
There are multiple test cases.
Each test case begins with two integers n and k, n indicates the number of stuff of the company.
Each of the following n-1 lines has two integers A and B, means A is the direct leader of B.
1 <= n <= 100 , 0 <= k < n
1 <= A, B <= n
Each test case begins with two integers n and k, n indicates the number of stuff of the company.
Each of the following n-1 lines has two integers A and B, means A is the direct leader of B.
1 <= n <= 100 , 0 <= k < n
1 <= A, B <= n
Output
For each test case, output the answer as described above.
Sample Input
7 2
1 2
1 3
2 4
2 5
3 6
3 7
Sample Output
2
Source
2015 Multi-University Training Contest 3
题目大意:输入的第一行:第一个数字n表示的是有几个人,第二个数字m表示查找管理两个人的。
接下去就有n-1行表示前面的管理后面的,最后求的就是有几个人是管理m个人的。
详见代码。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int n,m,Map[110][110]; 8 9 int dfs(int x)10 {11 int sum=0;12 for (int i=1;i<=n;i++)13 {14 if (Map[x][i]==1)15 {16 sum++;17 sum+=dfs(i);18 }19 }20 return sum;21 }22 23 int main()24 {25 int a,b,ans;26 while (~scanf("%d%d",&n,&m))27 {28 ans=0;29 memset(Map,0,sizeof(Map));30 //memset(ok,0,sizeof(ok));31 for (int i=1; i<=n-1; i++)32 {33 scanf("%d%d",&a,&b);34 Map[a][b]=1;35 }36 for (int i=1;i<=n;i++)37 {38 if (dfs(i)==m)39 ans++;40 }41 printf ("%d\n",ans);42 }43 return 0;44 }
0 0
- hdu 5326 Work(杭电多校赛第三场)
- hdu 5326 Work (2015多校第三场第11题) 暴力
- hdu 5319 Painter(杭电多校赛第三场)
- STD第三场 HDU 5326
- 2015多校联合训练第三场Work(hdu5326)
- 20150728多校第三场1011 - work
- 2015多校第三场hdu5326 work
- hdu 5326 Work(水)
- 【HDU】5326 - Work(拓扑)
- [dfs]多校联合第三场 K Work
- HDU 多校第三场
- hdu 5326 Work(并查集)
- hdu 5326 work (树的遍历)
- hdu 5326 - Work(递归)解题报告
- hdu Work 5326(并查集)
- HDU 5326 Work(并查集)
- hdu 5326 Work(并查集)
- HDU 5326 Work (并查集)
- 算法之匈牙利算法
- UVA 12545 Bits Equalizer
- hdu 1281 棋盘游戏(二分匹配)
- hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)
- 随记
- hdu 5326 Work(杭电多校赛第三场)
- su 与su -
- hdu 5319 Painter(杭电多校赛第三场)
- hdu 5328 Problem Killer(杭电多校赛第四场)
- hdu 1151 Air Raid(最小路径覆盖)
- HNU Joke with permutation (深搜dfs)
- hdu 1498 50 years, 50 colors(二分匹配_匈牙利算法)
- hdu 2119 Matrix(二分匹配)
- hdu 3729 I'm Telling the Truth(二分匹配_ 匈牙利算法)