Work

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 618    Accepted Submission(s): 412

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
 
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

//这题是要求管理了m个人的有多少个

//利用pre[]数组 记录每一个b的pre[b]为a; 接着从b到根的中的人掌控的个数+1 比如 

3 2   1  2    2  3   pre[2]=1; c[1]++ pre[3]=2; c[2]++-> pre[2]=1 c[1]++; 所以掌握个数为2的有一个c[1] 

#include <stdio.h>
#include <string.h>
int pre[110];
int c[110]; int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(c,0,sizeof(c));
for(int i=0;i<=n;i++)
pre[i]=i;
int a,b;
for(int i=0;i<n-1;i++)
{
scanf("%d%d",&a,&b);
pre[b]=a;
while(pre[b]!=b) //从b到根 每一个上级掌控人数加1。
{
b=pre[b];
c[b]++;
}
}
int cnt=0;
for(int i=1;i<=n;i++)
{
if(c[i]==m)
cnt++;
}
printf("%d\n",cnt);
}
return 0;
}

hdu 5326的更多相关文章

  1. HDU 5326(2015多校3)-Work(dfs)

    题目地址:pid=5326">HDU 5326 题意:给一张有向图n个点.n - 1(....输入n-1)条边. A指向B代表A管理B.然后能够间接管理,比方A管理B,B管理C.则A管 ...

  2. hdu 5326 Work

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Description It’s an interesting experience ...

  3. hdu 5326(基础题) work

    http://acm.hdu.edu.cn/showproblem.php?pid=5326 一道水题,题目大意是在公司里,给出n个员工和目标人数m,然后下面的n-1行是表示员工a管理b,问在这些员工 ...

  4. hdu 5326 Work(杭电多校赛第三场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. HDU 5326 work (回溯,树)

    题意:给一棵树,每个结点的子树下的结点都是它的统治对象,问有多少个统治对象数目为k的结点? 思路:每个结点都设一个cnt来记数,只要将每个结点往上回溯,直到树根,经过的每个结点都将计数器加1.最后再扫 ...

  6. ACM学习历程—HDU 5326 Work(树形递推)

    Problem Description It’s an interesting experience to move from ICPC to work, end my college life an ...

  7. 2015 Multi-University Training Contest 3 hdu 5326 Work

    Work Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. K - Work 分类: 比赛 2015-07-29 19:13 3人阅读 评论(0) 收藏

    K - Work Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  9. HDU OJ 5326 Work( 2015多校联合训练第3场) 并查集

    题目连接:戳ME #include <iostream> #include <cstdio> #include <cstring> using namespace ...

随机推荐

  1. python 与 mongodb的交互---查找

    python与mongo数据库交互时,在查找的时候注意的一些小问题: 代码: from pymongo import * def find_func(): #创建连接对象 client = Mongo ...

  2. python学习笔记 - for循环: 遍历字典, 分别打印key, value, key:value

    #遍历字典, 分别打印key, value, key:value emp = {'name':'Tom', 'age':20, 'salary' : 8800.00} for k in emp.key ...

  3. Linux网卡驱动

    <网络知识> a:网络模型               OSI模型               TCP模型 虽然OSI模型看着挺完美的,但是过于复杂,这样就会导致不实用,在Linux系统中 ...

  4. 自动打怪 c#

    其中思路很简单,单线程的一个乱七八糟的游戏 预计会更新背包,背包这个估计会用一个vector来存 图形的话,我得催催我的美工大人,她会帮我弄吧,哇哈哈 界面: namespace auttompk { ...

  5. Map:HashMap和TreeMap

    一.Map集合     特点:将键映射到值得对象 Map集合和Collection集合的区别? Collection:是单列集合,存储的是单独出现的元素    Map: 是双列集合,存储的是键值对形式 ...

  6. 使用NFS启动Tiny4412开发板根文件系统

      1.Ubuntu14.04上搭建NFS服务 1.1.安装NFS服务 $ sudo apt-get install nfs-kernel-server    //安装NFS服务 1.2 创建Tiny ...

  7. perf 工具介绍1

    https://perf.wiki.kernel.org/index.php/Tutorial http://os.51cto.com/art/201105/265133.htm 在LINUX 源代码 ...

  8. blurImage做图片模糊处理报错free(): invalid next size

    $image = new Imagick($url); $image->blurImage($x, $y); 调用blurImage($x, $y)函数报错: 原因是:原来的图片是CMYK的是印 ...

  9. Access-Control-Allow-Origin,跨域

    1.浏览器的同源安全策略 浏览器只允许请求当前域的资源,而对其他域的资源表示不信任.那怎么才算跨域呢? 请求协议http,https的不同 域domain的不同 端口port的不同 好好好,大概就是这 ...

  10. FitLayout

    <HTML> <HEAD> <TITLE>布局</TITLE> <link rel="stylesheet" type=&qu ...