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. 验证码60s倒计时前端效果

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 【线段树】【扫描线】Petrozavodsk Winter Training Camp 2018 Day 5: Grand Prix of Korea, Sunday, February 4, 2018 Problem A. Donut

    题意:平面上n个点,每个点带有一个或正或负的权值,让你在平面上放一个内边长为2l,外边长为2r的正方形框,问你最大能圈出来的权值和是多少? 容易推出,能框到每个点的 框中心 的范围也是一个以该点为中心 ...

  3. bzoj 1658: [Usaco2006 Mar]Water Slides 滑水

    题解: 很神奇的做法,把点分成入度大于出度和入度小于出度两种. 然后入度大于出度的点必须走到某个点,所以排序贪心. #include<stdio.h> #include<iostre ...

  4. BZOJ 1022 [SHOI2008]小约翰的游戏John AntiNim游戏

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1475  Solved: 932[Submit][ ...

  5. codecombat js

    #1 // Move to the gem. // Don't touch the walls! // Type your code below. this.moveRight(); this.mov ...

  6. [Visual Studio] VS2012调试时很慢的解决方案

      1.转自http://guooge.com/archives/408.html VS2010调试极慢获取出现死机,因为启动了IntelliTrace Visual Studio 2010 Ulti ...

  7. SET XACT_ABORT ON 数据库事务

    转载:http://www.cnblogs.com/rob0121/articles/2320932.html SET XACT_ABORT ON SET XACT_ABORT ON分为两种: 1.总 ...

  8. 求好用的在线手册编写工具,能编写像bootstrap在线Doc那种的,想为OpenCenter写个在线手册

    原文地址:http://www.oschina.net/question/1014458_225711 各位OSCer的开源项目的在线说明文档都是用什么写的呢? 类似 http://v3.bootcs ...

  9. Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!

    执行Maven Install打包的时候,提示以下警告信息: [WARNING] Using platform encoding (GBK actually) to copy filtered res ...

  10. Android之MVC——Model通知View去更新(实用)

    下面两段标红加深的代码是重点: import android.app.Activity; import android.os.Bundle; import android.view.View; imp ...