WorkTime
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 549 Accepted Submission (s): 375
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.
Inputthere 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
Outputfor each test case, output the answer as described above.
Sample Input
7 21 21 32 42 53 63 7
Sample Output
2
Source2015 multi-university Training Contest 3
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream>using namespace std;struct node{int u; int V; int next;} Edge[100000];int cnt;int head[1000],vis[1000],sum[1000];void Add (int u,int v) {edge[cnt].u=u; Edge[cnt].v=v; Edge[cnt].next=head[u]; head[u]=cnt++;} void Dfs (int u) {vis[u]=1; for (int i=head[u];i!=-1;i=edge[i].next) {int v=edge[i].v; if (vis[v]==0) {sum[u]++; DFS (v); SUM[U]+=SUM[V]; }}}int Main () {int n,k,i,a,b,v; while (scanf ("%d%d", &n,&k)!=eof) {cnt=0; memset (head,-1,sizeof (head)); for (i=1;i<=n-1;i++) {scanf ("%d%d", &a,&b); Add (A, b); } memset (Sum,0,sizeof (sum)); memset (vis,0,sizeof (VIS)); for (i=1;i<=n;i++) {if (vis[i]==0) {DFS (i); }} v=0; for (i=1;i<=n;i++) {if (sum[i]==k) {v++; }} printf ("%d\n", V); } return 0;}
Copyright NOTICE: This article is the original blogger article, if you have special needs, please contact Bo Master qq:793977586.
HDU 5326 Work