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. leetcode96 Unique Binary Search Trees

    题目: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For e ...

  2. css less

    LESSCSS是一种动态样式语言,属于CSS预处理语言的一种,它使用类似CSS的语法,为CSS的赋予了动态语言的特性,如变量.继承.运算.函数等,更方便CSS的编写和维护. LESSCSS可以在多种语 ...

  3. 多语言本地化开发Localized

    NSString * ViewsLocalizedStringFormat(NSString *key,NSString *defValue); // Handle localized strings ...

  4. ios app 解决微信扫二维码不能跳转问题

    <script> (function(){ // Setup GA (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i ...

  5. Leetcode: Max Sum of Rectangle No Larger Than K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  6. [转] JAVA多线程和并发基础面试问答

    JAVA多线程和并发基础面试问答 原文链接:http://ifeve.com/java-multi-threading-concurrency-interview-questions-with-ans ...

  7. 关于内存 GetMemory( ) 笔试分析

    1. #include<stdio.h>#include<string.h>void GetMemory(char *p){ p=(char *)malloc(100); }i ...

  8. CSS_03_01_CSS组合选择器

    CSS组合选择器 第01步:创建css:with.css @charset "utf-8"; /* 组合选择器,用","隔开 */ .a,.b,div span ...

  9. String.Format数字格式化参考

    String.Format数字格式化输出 {0:N2} {0:D2} {0:C2} (转) 数字 {0:N2} 12.36 数字 {0:N0} 13 货币 {0:c2} $12.36 货币 {0:c4 ...

  10. 夺命雷公狗---DEDECMS----2快速入门之玩转dede四大表之间的关系

    比如一个小说网站,网站里面有很多类型让我们的小说网他里面有很多种分类,如: 玄幻....奇幻....仙侠....武侠....文学....异界....都市....军事....历史....灵异....悬疑 ...