hdu 5326 Work
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5326
Work
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
统计子树大小为k的节点数。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
using std::set;
using std::pair;
using std::swap;
using std::queue;
using std::multiset;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = 110;
const int INF = 0x3f3f3f3f;
struct edge { int to, next; }G[N << 1];
bool inq[N];
int tot, size[N], head[N];
void init(int n) {
tot = 0;
rep(i, n + 1) {
head[i] = -1;
inq[i] = size[i] = false;
}
}
inline void add_edge(int u, int v) {
G[tot].to = v, G[tot].next = head[u], head[u] = tot++;
}
void dfs(int u) {
size[u] = 1;
for (int i = head[u]; ~i; i = G[i].next) {
edge &e = G[i];
dfs(e.to);
size[u] += size[e.to];
}
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int n, k, u, v;
while (~scanf("%d %d", &n, &k)) {
init(n);
rep(i, n - 1) {
scanf("%d %d", &u, &v);
add_edge(u, v);
inq[v] = true;
}
for(int i = 1; i <= n; i++) {
if (!inq[i]) {
u = i;
break;
}
}
int sum = 0;
dfs(u);
for (int i = 1; i <= n; i++) {
if (size[i] == k + 1) sum++;
}
printf("%d\n", sum);
}
return 0;
}
hdu 5326 Work的更多相关文章
- HDU 5326(2015多校3)-Work(dfs)
题目地址:pid=5326">HDU 5326 题意:给一张有向图n个点.n - 1(....输入n-1)条边. A指向B代表A管理B.然后能够间接管理,比方A管理B,B管理C.则A管 ...
- hdu 5326(基础题) work
http://acm.hdu.edu.cn/showproblem.php?pid=5326 一道水题,题目大意是在公司里,给出n个员工和目标人数m,然后下面的n-1行是表示员工a管理b,问在这些员工 ...
- hdu 5326 Work(杭电多校赛第三场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 5326 work (回溯,树)
题意:给一棵树,每个结点的子树下的结点都是它的统治对象,问有多少个统治对象数目为k的结点? 思路:每个结点都设一个cnt来记数,只要将每个结点往上回溯,直到树根,经过的每个结点都将计数器加1.最后再扫 ...
- hdu 5326
Work Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- ACM学习历程—HDU 5326 Work(树形递推)
Problem Description It’s an interesting experience to move from ICPC to work, end my college life an ...
- 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 Submis ...
- K - Work 分类: 比赛 2015-07-29 19:13 3人阅读 评论(0) 收藏
K - Work Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU OJ 5326 Work( 2015多校联合训练第3场) 并查集
题目连接:戳ME #include <iostream> #include <cstdio> #include <cstring> using namespace ...
随机推荐
- 【小错误】起归档是遇到ORA-00265: instance recovery required, cannot set ARCHIVELOG mode
今天在起归档时遇到ORA-00265: instance recovery required, cannot set ARCHIVELOG mode的错误 从错误我们能够看到是由于datafile,c ...
- 【测试】并使用scott用户下的emp表写一条SQL语句,执行计划走唯一索引
SQL; SAL ---------- Execution Plan ---------------------------------------------------------- ------ ...
- 第三方登录 QQ登录 人人网登录 新浪微博登录
http://www.pp6.cn/Index.aspx http://www.pp6.cn/Login.aspx 网站有自己的账号系统,这里使用的第三方登录仅仅是获取第三方账号的唯一id,昵称,性别 ...
- 多文件目录下makefile文件递归执行编译所有c文件
首先说说本次嵌套执行makefile文件的目的:只需make根目录下的makefile文件,即可编译所有c文件,包括子目录下的. 意义:自动化编译行为,以后编译自己的c文件时可把这些makefile文 ...
- 不安装Oracle客户端使用PL/SQL连接服务器端Oracle
从10G开始,Oracle 提供了一个较为轻量级的客户包,叫做Instant Client Package. 将它安装好后,就不用再安装庞大的Oracle客户端,可以直接通过使用PL/SQL连接服务器 ...
- 改变ListCtrl某行的背景色或者字体颜色
大家也许熟悉WM_NOTIFY,控件通过WM_NOTIFY向父窗口发送消息.在WM_NOTIFY消息体中,部分控件会发送NM_CUSTOMDRAW告诉父窗口自己需要绘图. 也可以反射NM_CUSTOM ...
- SPSS时间序列:频谱分析
一.频谱分析(分析-预测-频谱分析) “频谱图”过程用于标识时间序列中的周期行为.它不需要分析一个时间点与下一个时间点之间的变异,只要按不同频率的周期性成分分析整体序列的变异.平滑序列在低频率具有更强 ...
- 入门学习PHP之变量_1
1.函数里只能访问局部变量,不能访问全局变量,如果函数里需要访问全局变量则需要在变量前加global作用域,如下实例: <?php $x=5; $y=10; function myTest() ...
- Win8系统安装NET Framework 3.5的方法
1)找到下载过的Win8系统盘,解压到某个目录下,例如 F:, 找到解压的系统盘目录中"sources\sxs"文件夹 2)以管理员身份运行cmd命令,执行下面的命令: dism. ...
- EXT格式误删除恢复
http://hatemysql.com/ 1.从/proc文件系统恢复数据#lsof |grep -i deletecat 11791 root 1w REG 253,0 94 1048589 /h ...