2015 Multi-University Training Contest 3 hdu 5326 Work
Work
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 306 Accepted Submission(s): 217

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.
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
#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的更多相关文章
- 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 ...
- 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: ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- pythone 学习笔记(粗略)
文档目录 概述 安装 基本语法 数据结构 4.1 数字和字符串类型 4.2 元祖 4.3 列表 4.4 字典 流程语句 5.1 分支结构 5.2 逻辑运算符(if) 5.3 循环 5.3.1 for ...
- pytorch 1 torch_numpy, 对比
import torch import numpy as np details about math operation in torch can be found in: http://pytorc ...
- Shiro:初识Shiro及简单尝试
Shiro 一.什么是Shiro Apache Shiro是Java的一个安全(权限)框架 作用:认证.授权.加密.会话管理.与web集成.缓存等 下载地址:http://shiro.apache.o ...
- 2015 Multi-University Training Contest 5 hdu 5352 MZL's City
MZL's City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- CODEVS——T 1269 匈牙利游戏 2012年CCC加拿大高中生信息学奥赛
http://codevs.cn/problem/1269/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Descript ...
- Intellij IDEA插件 - Scroll From Source
Intellij IDEA插件 - Scroll From Source 学习了:http://blog.csdn.net/luonanqin/article/details/41088171 可以自 ...
- hdu 3449 Consumer (依赖01背包)
题目: 链接:pid=3449">点击打开链接 题意: 思路: dp[i][j]表示前i个箱子装j钱的材料可以得到的最大价值. 代码: #include<iostream> ...
- [Maven实战](5)Archetype生成项目骨架
Hello World项目中有一些Maven的约定:在项目根文件夹中放置pom.xml,在src/main/java文件夹下放置项目的主代码,在sc/test/java中放置项目的測试代码.之所以一步 ...
- Sping框架中的注解详解
传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...
- 计算sigma
1.计算平均值Avg Avg = (a0 + a1 + ......+ an-1) / n 2.计算sigma sigma = sqrt( ( (a0-avg) ^2 + (a1-avg) ^2 ...