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字符串的GZIP压缩解压缩

    package com.gzip; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import ...

  2. 文件操作 & 重定向

    实例:输入一些整数,求出它们的最小值.最大值和平均值(保留3位小数).输入保证这些数都是不超过1000的整数. 分析:需要注意的几点:数据个数不确定:数据大小不确定.简单分析后编程如下: #inclu ...

  3. PostgreSQL Cascade Replication

    PostgreSQL Cascade Replication node1:master:10.2.208.10:repclia(user) node2:upstreamnode:10.2.208.11 ...

  4. ligerui_ligerTree_001_第一个“树”效果

    折叠.展开.有复选框.没有复选框: 源码地址:http://download.csdn.net/detail/poiuy1991719/8571255 效果图: <%@ page languag ...

  5. struts.xml什么时候加载

    http://www.cnblogs.com/jiemoxiaodi/p/5621697.html

  6. Oracle游标总结

    1.声明游标 declare teacher_id ); teacher_name ); teacher_title ); teacher_sex ); cursor teacher_cur is ; ...

  7. logging

    #coding=utf8 import sys, logging   logging.basicConfig(level=logging.INFO,                     forma ...

  8. PHP生成二维码【谷歌API+qrcode+圆角Logo】

    方法一:谷歌二维码API 接口地址:https://chart.googleapis.com/chart 官方文档:https://developers.google.com/chart/infogr ...

  9. 运行eclipse提示 The requested resource () is not available.

    不识别web-inf目录,把文件放在Webcontent下就可以运行. 放在其他文件夹里也可以识别.

  10. Sql Server 2012 的新分页方法分析(offset and fetch) - 转载

    最近在分析 Sql Server 2012 中 offset and fetch 的新特性,发现 offset and fetch 无论语法的简洁还是功能的强大,都是相当相当不错的 其中 offset ...