Work

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

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
 
Source
 
解题:一顿乱搞
 
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct arc {
int to,next;
arc(int x = ,int y = -) {
to = x;
next = y;
}
} e[maxn];
int head[maxn],tot;
void add(int u,int v) {
e[tot] = arc(v,head[u]);
head[u] = tot++;
e[tot] = arc(u,head[v]);
head[v] = tot++;
}
int ind[maxn],cnt[maxn],ret,n,k;
void dfs(int u,int fa) {
cnt[u] = ;
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].to == fa) continue;
dfs(e[i].to,u);
cnt[u] += cnt[e[i].to];
}
if(k + == cnt[u]) ++ret;
}
int main() {
int u,v;
while(~scanf("%d%d",&n,&k)) {
memset(head,-,sizeof head);
memset(ind,,sizeof ind);
ret = tot = ;
for(int i = ; i < n; ++i) {
scanf("%d%d",&u,&v);
add(u,v);
++ind[v];
}
for(int i = ; i <= n; ++i)
if(!ind[i]) {
dfs(i,-);
break;
}
printf("%d\n",ret);
}
return ;
}

最新文章

  1. “此网页上的某个 Web 部件或 Web 表单控件无法显示或导入。找不到该类型,或该类型未注册为安全类型。”
  2. 解决svn问题:Wrong committed revision number: -1
  3. pdb调试技巧
  4. Moon.Orm 5.0(MQL版)分页功能的设计(求指教,邀请您的加入)
  5. Objective-C 谈谈深浅拷贝,copy和mutable copy都不是完全拷贝
  6. 递归问题==优化 还有数据库sqlreader
  7. 解决SaveChanges会Hold住之前的错误的问题
  8. mac 配置jdk maven
  9. mysql中在表中insert数据时,有重复主键id时,变成update
  10. jQuery - 设置内容和属性
  11. system函数
  12. [原]sdut2624 Contest Print Server (大水+大坑)山东省第四届ACM省赛
  13. POJ 1904 King&#39;s Quest 强连通分量+二分图增广判定
  14. Java_JVM学习笔记(深入理解Java虚拟机)___重点
  15. OpenJudge/Poj 1661 帮助 Jimmy
  16. C#中的StringBuilder
  17. Java 简单实用方法二
  18. nyoj 第几是谁
  19. Tmux的快捷键
  20. ALINX公众号

热门文章

  1. pytorch 7 save_reload 保存和提取神经网络
  2. 2019-03-20 用SSIS把Excel中的数据导出来保存到SQLServer中
  3. 【henuacm2016级暑期训练-动态规划专题 C】Little Girl and Maximum XOR
  4. 极路由4pro(HC5962)安装python
  5. Eclipse 更新Android SDK后,新建项目出现appcompat_v7project的相关问题
  6. JAVA设计模式之【职责链模式】
  7. iOS (封装)一句话调用系统的alertView和alertController
  8. 【转】Android 服务器之SFTP服务器上传下载功能 -- 不错
  9. [JZOJ 5894] [NOIP2018模拟10.5] 同余方程 解题报告(容斥)
  10. html 移动端关于长按图片弹出保存问题