用了前面一题的写法,练一下熟练度
#include <iostream>
using namespace std;
const int N = 110;
int n, m;
bool g[N][N];
bool has_father[N];
int q[N];
int max_sum = 1;
int cnt = 1;
int max_cnt = 1;
void bfs(int root)
{
int hh = 0, tt = 0;
q[0] = root;
while ( hh <= tt )
{
int head = hh, tail = tt, sum = 0;
while ( hh <= tail )
{
int t = q[hh++];
for ( int i = 1; i <= n; i ++ )
{
if ( g[t][i] == true )
{
q[++tt] = i;
sum++;
}
}
}
cnt ++;
if ( sum > max_sum )
{
max_sum = max(max_sum, sum);
max_cnt = cnt;
}
}
}
int main()
{
cin >> n >> m;
for ( int i = 0; i < m; i ++ )
{
int node, num;
cin >> node >> num;
while ( num -- )
{
int son;
cin >> son;
has_father[son] = true;
g[node][son] = true;
}
}
int root = 1;
while ( has_father[root] )root++;
bfs(root);
cout << max_sum << ' ' << max_cnt << endl;
return 0;
}