無限の光を放つのは人間の心であり、無限の闇を生み出すのも人間の心であり、光と闇が絡み合って戦うこの世界は、懐かしくて無力な世界です。
ファミリー階層は、通常、家系図によって提示され、同じレベルのすべてのノードが同じ世代に属します。あなたの仕事は、最大の人口を持つ世代を見つけることです。
入力仕様:
各入力ファイルには1つのテストケースが含まれています。各ケースは、ツリー内のファミリーメンバーの総数である2つの正の整数N(<100)で始まります(したがって、すべてのメンバーに01からNまでの番号が付けられていると仮定します)、およびM(<N)は、子供がいる家族。次にM行が続き、それぞれに次の形式で家族の情報が含まれます。
ID K ID[1] ID[2] ... ID[K]
ここで、 ID
は家族のメンバーを表す2桁の数字、 K
(> 0)は彼/彼女の子供の数、それに続く彼/彼女の子供の2桁ID
のシーケンスです 。簡単にするために、ルートID
をに 修正してみましょう 01
。行内のすべての数値はスペースで区切られています。
出力仕様:
各テストケースについて、最大の母集団数と対応する世代のレベルを1行に出力します。このような世代は一意であると想定され、ルートレベルは1として定義されます。
入力例:
23 13
21 1 23
01 4 03 02 04 05
03 3 06 07 08
06 2 12 13
13 1 21
08 2 15 16
02 2 09 10
11 2 19 20
17 1 22
05 1 11
07 1 14
09 1 17
10 1 18
出力例:
9 4
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
//#include<bits/stdc++.h>
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
typedef long long ll;
using namespace std;
int const mod=1e9+7;
const int maxn=110;
vector<int> T[maxn];
int n,m,hs[maxn]={0},mx=0;
int id,k,tmp,ct;
void dfs(int root, int dh)
{
hs[dh]++;
if(T[root].size()==0)
return ;
for(int i=0;i<T[root].size();i++)
dfs(T[root][i],dh+1);
}
int main()
{
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>id>>k;
for(int i=0;i<k;i++)
{
cin>>tmp;
T[id].push_back(tmp);
}
}
dfs(1,1);
for(int i=0;i<maxn;i++)
{
if(hs[i]>mx)
{
ct=i;
mx=hs[i];
}
}
cout<<mx<<' '<<ct<<endl;
return 0;
}