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 ;
}

2015 Multi-University Training Contest 3 hdu 5326 Work的更多相关文章

  1. 2015 Multi-University Training Contest 8 hdu 5390 tree

    tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...

  2. 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!

    Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID:  ...

  3. 2015 Multi-University Training Contest 8 hdu 5385 The path

    The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...

  4. 2015 Multi-University Training Contest 3 hdu 5324 Boring Class

    Boring Class Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  5. 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ

    RGCDQ Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  6. 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple

    CRB and Apple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  7. 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries

    CRB and Queries Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  8. 2015 Multi-University Training Contest 6 hdu 5362 Just A String

    Just A String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence

    Easy Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

随机推荐

  1. HDU 2150 Pipe( 判断线段相交水 )

    链接:传送门 题意:略 思路:数据量很小,直接暴力所有线段 /********************************************************************* ...

  2. BZOJ 2119 股市的预测 (后缀数组+RMQ)

    题目大意:求一个字符串中形如$ABA$的串的数量,其中$B$的长度是给定的 有点像[NOI2016]优秀的拆分这道题 先对序列打差分,然后离散,再正反跑$SA$,跑出$st$表 进入正题 $ABA$串 ...

  3. pytorch 7 optimizer 优化器 加速训练

    import torch import torch.utils.data as Data import torch.nn.functional as F import matplotlib.pyplo ...

  4. WinServer-IIS-FTP服务器

    在设置FTP服务器的时候,注意SSL的设置,简单尝试的话,不需要启用SSL 常用FTP命令 ftp   进入FTP命令模式 open 192.168.10.6     (连接到FTP主机,或者open ...

  5. Android View 事件分发机制 源代码解析 (上)

    一直想写事件分发机制的文章,无论咋样,也得自己研究下事件分发的源代码.写出心得~ 首先我们先写个简单的样例来測试View的事件转发的流程~ 1.案例 为了更好的研究View的事件转发,我们自定以一个M ...

  6. HTTP Status 404 - /servlet/Item/AddItemServlet

    我想学习编程的人对404和500都是非常敏感非常熟悉的.在做DRP系统的时候多次遇到这两个错误,今天让我遇到他并且让我铭记他,那就是一个"/": 这是说jsp出问题了,并且找不到, ...

  7. Android使用有道翻译API实如今线翻译功能

    在Android应用中,加入在线翻译的功能,这里调用的是有道翻译的API. 使用有道翻译API.首先要申请一个key,申请地址为:path=data-mode">有道翻译API申请地址 ...

  8. elasticsearch如何安全重启

    elasticsearch如何安全重启节点 问题: elasticsearch集群,有时候可能需要修改配置,增加硬盘,扩展内存等操作,需要对节点进行维护升级.但是业务不能停,如果直接kill掉节 点, ...

  9. Python入门机器学习

    如何通过Python入门机器学习 我们都知道机器学习是一门综合性极强的研究课题,对数学知识要求很高.因此,对于非学术研究专业的程序员,如果希望能入门机器学习,最好的方向还是从实践触发. 我了解到Pyt ...

  10. Windows下本机简易监控系统搭建(Telegraf+Influxdb+Grafana)--转

    原文地址:http://www.cnblogs.com/liugh/p/6683488.html 一.文件准备 1.1 文件名称 telegraf-1.2.1_windows_amd64.zip in ...