-
Notifications
You must be signed in to change notification settings - Fork 2
/
A1094.cpp
59 lines (55 loc) · 1.04 KB
/
A1094.cpp
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
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 110;
int N, M;
int cnt[MAXN] = {0};
struct Node{
int level;
vector<int> child;
} node[MAXN];
void levelOrder(int root){
queue<int> q;
q.push(root);
node[root].level = 1;
while(!q.empty()){
int front = q.front();
q.pop();
++cnt[node[front].level];
for(int i = 0; i < node[front].child.size(); ++i){
int child = node[front].child[i];
q.push(child);
node[child].level = node[front].level + 1;
}
}
}
void DFS(int index, int level){
++cnt[level];
for(int i = 0; i < node[index].child.size(); ++i){
DFS(node[index].child[i], level+1);
}
}
int main(){
scanf("%d%d", &N, &M);
for(int i = 0; i < M; ++i){
int id, k, child;
scanf("%d%d", &id, &k);
for(int j = 0; j < k; ++j){
scanf("%d", &child);
node[id].child.push_back(child);
}
}
//levelOrder(1);
DFS(1, 1);
int maxL = -1;
int level = -1;
for(int i = 1; i <= N; ++i){
if(cnt[i] > maxL){
maxL = cnt[i];
level = i;
}
}
printf("%d %d", maxL, level);
return 0;
}