Work
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): Accepted submission (s):
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 have a title, everyone except the boss have a direct leader, and all the Relati Onship forms a tree. If a ' s title is higher than B (A was the direct or indirect leader of B), we call it A manages B.
Now, give you the relation for a company, can-calculate how many people manage k people.
Input There is multiple test cases.
Each test case is begins with a integers n and k, n indicates the number of stuff of the company.
Each of the following n-1 lines have both integers a and B, means a is the direct leader of B.
1 <= N <=, 0 <= k < n
1 <= A, B <= N
Output for each test case, output the answer as described above. Sample Input
7 21 21 32 42 53 63 7
Sample Output
2
Source multi-university Training Contest 3
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5326
To give a tree, the point is the employment relationship a B means A is a B boss, ask a few people have K of subordinates
Topic Analysis: Multi-school registration, casually calculate
#include <cstdio> #include <cstring>int const MAX = 105;struct edge{int v, Next;} E[max];int Head[max], Num[max];bool In[max], vis[max];int cnt, Ans;int N, k;void Add (int u, int v) {e[cnt].v = v; E[cnt].next = Head[u]; Head[u] = cnt + +;} void DFS (int u) {Vis[u] = true; Num[u] = 0; for (int i = head[u]; i =-1; i = e[i].next) {int v = E[I].V; if (!vis[v]) {DFS (v); Num[u] + = (Num[v] + 1); }} if (num[u] = = k) ans + +; return;} int main () {while (scanf ("%d%d", &n, &k)! = EOF) {cnt = 0; Ans = 0; Memset (Head,-1, sizeof (head)); Memset (in, False, sizeof (in)); Memset (Vis, false, sizeof (VIS)); for (int i = 0; i < n-1; i++) {int u, v; scanf ("%d%d", &u, &v); ADD (U, v); IN[V] + +; } for (int i = 1; I <= n; i++) if (in[i] = = 0) DFS (i); printf ("%d\n", ans); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5326 Work (Basic tree DP)