使用广度优先算法第二个测试点过不去
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int maxn = 101;
struct node{
int layer;
vector<int> child;
}Node[maxn];
int n, m, father, child, k, rec[maxn] = {0};
// void BFS(int root){
// queue<int> q;
// q.push(root);
// Node[root].layer = 1;
// while(!q.empty()){
// int front = q.front();
// q.pop();
// for(int i = 0; i < Node[front].child.size(); i++){
// int child = Node[front].child[i];
// Node[child].layer = Node[front].layer + 1;
// rec[Node[child].layer]++;
// q.push(child);
// }
// }
// }
void DFS(int index, int level){
rec[level]++;
for(int i = 0; i < Node[index].child.size(); i++)
DFS(Node[index].child[i], level + 1);
}
int main(){
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> father >> k;
for(int j = 0; j < k; j++){
cin >> child;
Node[father].child.push_back(child);
}
}
//BFS(1);
DFS(1, 1);
int max = -1, mind;
for(int i = 0; i < maxn; i++){
if(rec[i] > max){
max = rec[i]; mind = i;
}
}
cout << max << " " << mind;
return 0;
}