-
Notifications
You must be signed in to change notification settings - Fork 0
/
1004.c
67 lines (54 loc) · 1.43 KB
/
1004.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#define MAXN 100 + 10
typedef struct Node {
int id;
struct Node *fa;
struct Node *ch, *next;
int depth;
} Node;
Node nodes[MAXN];
void addChild(Node *fa, Node *ch) {
ch->fa = fa;
ch->next = fa->ch;
fa->ch = ch;
}
void dfs(Node *x) {
for (Node *ch = x->ch; ch; ch = ch->next) {
ch->depth = x->depth + 1;
dfs(ch);
}
}
int ans[MAXN];
int main() {
int n, m;
while (scanf("%d%d", &n, &m) != EOF && n != 0) {
for (int i = 0; i < m; i++) {
int fa;
scanf("%d", &fa);
int k;
scanf("%d", &k);
for (int i = 0; i < k; i++) {
int id;
scanf("%d", &id);
addChild(nodes + fa, nodes + id);
}
}
for (int i = 1; i <= n; i++) {
if (nodes[i].fa == NULL) {
nodes[i].depth = 0;
dfs(nodes + i);
break;
}
}
int maxDepth = 0;
for (int i = 1; i <= n; i++) {
if (nodes[i].ch == NULL) ans[nodes[i].depth]++;
maxDepth = (nodes[i].depth > maxDepth ? nodes[i].depth : maxDepth);
}
for (int i = 0; i <= maxDepth; i++) {
if (i == maxDepth) printf("%d\n", ans[i]);
else printf("%d ", ans[i]);
}
}
return 0;
}