#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
struct node
{
int data;
vector<int> child;
}A[110];
int N,M;
int maxnum=-1,maxlevel=-1;
void levelorder(int root)
{
queue<int> q;
q.push(root);
int preend=root,last=root;
int level=1,numg=0;
while(!q.empty())
{
int top=q.front();
q.pop();
numg++;
for(int i=0;i<A[top].child.size();i++)
{
q.push(A[top].child[i]);
last=A[top].child[i];
}
if(top==preend)
{
if(numg>maxnum)
{
maxnum=numg;
maxlevel=level;
}
level++;
preend=last;
numg=0;
}
}
}
int main()
{
scanf("%d%d",&N,&M);
for(int i=0;i<M;i++)
{
int parent,numc;
scanf("%d%d",&parent,&numc);
for(int j=0;j<numc;j++)
{
int c;
scanf("%d",&c);
A[parent].child.push_back(c);
}
}
levelorder(1);
printf("%d %d",maxnum,maxlevel);
return 0;
}
PAT甲1094 The Largest Generation(25 分)
最新推荐文章于 2021-11-30 19:17:15 发布