CODE:

#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; bool mat[105][105];
bool root[105];
int n,m;
int R;
int cnt[105];
int ans1,ans2; struct TNode
{
int num;
int level;
}; void BFS()
{
queue<TNode> Q;
TNode first;
first.num=R;
first.level=1;
TNode next;
Q.push(first);
while(!Q.empty())
{
first=Q.front();
cnt[first.level]++;
Q.pop();
for(int j=1;j<=n;j++)
{
if(mat[first.num][j]==true)
{
next.num=j;
next.level=first.level+1;
Q.push(next);
}
}
}
for(int i=1;i<=n;i++)
{
if(ans1<cnt[i])
{ans1=cnt[i];
ans2=i;
}
}
} int main()
{
int id,k;
while(scanf("%d%d",&n,&m)==2)
{
memset(mat,false,sizeof(mat));
memset(root,true,sizeof(root));
memset(cnt,0,sizeof(cnt));
int flag=0;
for(int i=1;i<=m;i++)
{
scanf("%d%d",&id,&k);
int id1;
while(k--)
{
scanf("%d",&id1);
mat[id][id1]=true;
root[id1]=false;
}
for(int i=1;i<=n;i++)
{
if(root[i]==true)
{
for(int j=1;j<=n;j++)
{
if(mat[i][j]==true)
{
flag=1;
R=i;
break;
}
}
}
if(flag)
break;
}
}
ans1=-1;
BFS();
printf("%d %d\n",ans1,ans2);
}
return 0;
}

PAT 1094. The Largest Generation(BFS)的更多相关文章

  1. PAT 1094 The Largest Generation[bfs][一般]

    1094 The Largest Generation(25 分) A family hierarchy is usually presented by a pedigree tree where a ...

  2. PAT 1094. The Largest Generation (层级遍历)

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

  3. PAT甲级——1094 The Largest Generation (树的遍历)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...

  4. 1094 The Largest Generation ——PAT甲级真题

    1094 The Largest Generation A family hierarchy is usually presented by a pedigree tree where all the ...

  5. PTA甲级1094 The Largest Generation (25分)

    PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...

  6. PAT (Advanced Level) Practise - 1094. The Largest Generation (25)

    http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...

  7. PAT Advanced 1094 The Largest Generation (25) [BFS,DFS,树的遍历]

    题目 A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level ...

  8. PAT A1094 The Largest Generation (25 分)——树的bfs遍历

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

  9. PAT 甲级 1094 The Largest Generation

    https://pintia.cn/problem-sets/994805342720868352/problems/994805372601090048 A family hierarchy is ...

随机推荐

  1. 初识Pyhon之准备环境

    安装成功python的运行环境之后,你可能要迫不及待大展身手了 如果你有一定的语言基础,那么基础这一块儿就可以简单的看看就可以了,但是你是一个编程语言的初学者.不着急,慢慢往下看 打开pycharm创 ...

  2. (转)UITextField

    //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...

  3. 与LCD_BPP相关的函数

    board/freescale/mx6q_sabresd/mx6q_sabresd.c:    panel_info.vl_bpix = LCD_BPP; common/lcd.c:   off  = ...

  4. cocos2d心得关于精灵帧缓存

    在cocos2d中,精灵帧缓存CCSpriteFrameCache是用来存储精灵帧的.它没有特别的属性,只存储了一些用来管理CCSpriteFrame的方法. 以一个例子来说明,一般在又纹理图集的程序 ...

  5. POJ:3461-Oulipo(KMP模板题)

    原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...

  6. Java面试——String、StringBuider以及StringBuffer的区别和使用场景

    1.  String.StringBuider.StringBuffer的区别  String是不可变的对象,因此在每次对String类型进行改变的时候,都会生成一个新的String对象,然后将指针指 ...

  7. saltstack管理八之常用执行模块

    所有执行模块: http://docs.saltstack.cn/zh_CN/latest/ref/states/all/index.html 常用模块:cmd, cron, file, mount, ...

  8. pytorch中的math operation: torch.bmm()

    torch.bmm(batch1, batch2, out=None) → Tensor Performs a batch matrix-matrix product of matrices stor ...

  9. Flutter 发布APK时,release版本和debug版本的默认权限不同

    Flutter 发布APK时,release版本和debug版本的默认权限不同 @author ixenos 在调试模式下,默认情况下启用服务扩展和多个权限(在flutter中) 当您处于发布模式时, ...

  10. iOS视图边框的简单做法

    我们绘制UI界面的时候,一般我们做边框是用layer,然后再给它上面添加阴影什么的,我比较喜欢用下面这个方法, UI弄几张边框的图片,用代码给图片拉伸 - (UIImage *)changeBorde ...