[原创]HDU 5326 多维数组接法 【并查集】
[原创]HDU 5326 多维数组接法 【并查集】
2016-01-23 18:40:20 Tabris_ 阅读数:284
博客爬取于2020-06-14 22:45:11
以下为正文
版权声明:本文为Tabris原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/50570897
A - Work
Time Limit: 1000 MS Memory Limit: 32768 KB 64bit IO Format: %I64d &
%I64u
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
2 4
1 3 2 5
3 7
3 6
Sample Output
2
题目就是给了一堆数,分别对应一个人,然后吧就是A领导B,最后让你求出有K个手下的人的个数。(开始翻译成了求K的手下有几个。。英语不好真苦逼啊)。。。
本题其实是一道并查集的题目,但是并查集并没有写明白,所以用了苦逼的多维数组。。。
详情请看代码。。。
然后开始贴代码
1 |
|