K - Work

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d
& %I64u

Appoint description: 
System Crawler  (2015-07-28)

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
题意就是,有n个人,判断有几个人领导的人数是k,
输入两个数,前面的领导后面的;
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm> using namespace std; const int MAX = 110; int Map[MAX][MAX]; int Dp[MAX]; int n,k; int DFS(int s)//DFS搜索每个人所领导的人数;
{
if(Dp[s])
{
return Dp[s];
}
int sum=0;
for(int i=1;i<=n;i++)
{
if(Map[s][i])
{
sum++;
sum+=DFS(i);
}
}
Dp[s]=sum;
return Dp[s];
} int main()
{
int a,b;
while(~scanf("%d %d",&n,&k))
{
memset(Map,0,sizeof(Map));
memset(Dp,0,sizeof(Dp));
for(int i=1;i<n;i++)
{
scanf("%d %d",&a,&b);
Map[a][b]=1;
}
int ans=0;
for(int i=1;i<=n;i++)
{
if(DFS(i)==k)
{
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

K - Work 分类: 比赛 2015-07-29 19:13 3人阅读 评论(0) 收藏的更多相关文章

  1. 欧拉通路-Play on Words 分类: POJ 图论 2015-08-06 19:13 4人阅读 评论(0) 收藏

    Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10620 Accepted: 3602 Descri ...

  2. Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. 二分图匹配 分类: ACM TYPE 2014-10-01 19:57 94人阅读 评论(0) 收藏

    #include<cstdio> #include<cstring> using namespace std; bool map[505][505]; int n, k; bo ...

  4. Can you find it? 分类: 二分查找 2015-06-10 19:55 5人阅读 评论(0) 收藏

    Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...

  5. Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏

    Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...

  6. Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏

    Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...

  7. 迷之节约 分类: sdutOJ 最小生成树 2015-06-24 19:10 10人阅读 评论(0) 收藏

    迷之节约 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 FF超级有钱,最近又买了n个(1 <= n <= 300)小岛,为 ...

  8. 菊花加载第三方--MBprogressHUD 分类: ios技术 2015-02-05 19:21 120人阅读 评论(0) 收藏

    上次说到了网络请求AFN,那么我们在网络请求的时候,等待期间,为了让用户不认为是卡死或程序出错,一般都会放一个菊花加载,系统有一个菊花加载类叫UIProgressHUD.但是我今天要说的是一个替代它的 ...

  9. 浅谈IOS8之size class 分类: ios技术 2015-02-05 19:06 62人阅读 评论(0) 收藏

    文章目录 1. 简介 2. 实验 3. 实战 3.1. 修改 Constraints 3.2. 安装和卸载 Constraints 3.3. 安装和卸载 View 3.4. 其他 4. 后话 以前和安 ...

随机推荐

  1. Java内存分配全面浅析

    本文将由浅入深详细介绍Java内存分配的原理,以帮助新手更轻松的学习Java.这类文章网上有很多,但大多比较零碎.本文从认知过程角度出发,将带给读者一个系统的介绍. 进入正题前首先要知道的是Java程 ...

  2. nyist 676 小明的求助

    http://acm.nyist.net/JudgeOnline/problem.php?pid=676 小明的求助 时间限制:2000 ms  |  内存限制:65535 KB 难度:2   描述 ...

  3. 关于 static 的用途

    1.三个作用 第一个作用是 隐藏 输出: Hello 所有未加static前缀的全局变量和函数都具有全局可见性,其它的源文件也能访问.此例中,a是全局变量,msg是函数,并且都没有加static前缀, ...

  4. php session memcache

    ini_set("session.save_handler", "memcache"); ini_set("session.save_path&quo ...

  5. BackgroundWorker的使用

    一个程序中需要进行大量的运算,并且需要在运算过程中支持用户一定的交互,为了获得更好的用户体验,使用BackgroundWorker来完成这一功能.   基本操作: bgw.RunWorkerAsync ...

  6. paper 12:机器学习常见算法分类汇总

    机器学习无疑是当前数据分析领域的一个热点内容.很多人在平时的工作中都或多或少会用到机器学习的算法.这里南君先生为您总结一下常见的机器学习算法,以供您在工作和学习中参考. 机器学习的算法很多.很多时候困 ...

  7. PAT乙级 1007. 素数对猜想 (20)

    1007. 素数对猜想 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 让我们定义 dn 为:dn = ...

  8. linux中使用软链接时出现 too many levels of symbolic links

    刚开始使用的源文件的路径是相对路径,所以导致标题中的这种错误. 只要用绝对路径表示源文件就好了.如果用相对路径的话,实际相对的是目标文件所在的路径,而在创建链接文件时用的路径是相对于当前的路径.

  9. C++中关于无法解析的外部符号问题LNK2019问题的总结

           网上一般有很全面的解决方法,最近恰好本道长也遇到了这种问题,也恰好解决了,这种问题应该算作配置问题,而非程序本身问题,多数是因为接手了生疏的程序导致,此问题看上去很简单,但木有经验的话很 ...

  10. MessageDigest

    转: 我们知道,编程中数据的传输,保存,为了考虑安全性的问题,需要将数据进行加密.我们拿数据库做例子.如果一个用户注册系统的数据库,没有对用户的信息进 行保存,如,我去页面注册,输入"Vic ...