-
Notifications
You must be signed in to change notification settings - Fork 0
/
1094.cpp
52 lines (52 loc) · 1.04 KB
/
1094.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
//
// main.cpp
// test
//
// Created by 李寻欢 on 2019/9/26.
// Copyright © 2019 李寻欢. All rights reserved.
//
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <unordered_map>
#include <string.h>
using namespace std;
int n,m,t,k,son; // root = 1
unordered_map<int, vector<int>> tree;
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<m;++i){
scanf("%d%d",&t,&k);
while (k--) {
scanf("%d",&son);
tree[t].push_back(son);
}
}
queue<int> q;
q.push(1);
int ans = 0;
int level = 1;
int cnt = 0;
while (q.size()) {
cnt++;
int size = (int)q.size();
if (size > ans){
ans = size;
level = cnt;
}
while (size--) {
int temp = q.front();
q.pop();
for(auto son:tree[temp]){
q.push(son);
}
}
}
printf("%d %d",ans,level);
}