PAT 1094. The Largest Generation(BFS)
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)的更多相关文章
- PAT 1094 The Largest Generation[bfs][一般]
1094 The Largest Generation(25 分) A family hierarchy is usually presented by a pedigree tree where a ...
- PAT 1094. The Largest Generation (层级遍历)
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
- PAT甲级——1094 The Largest Generation (树的遍历)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...
- 1094 The Largest Generation ——PAT甲级真题
1094 The Largest Generation A family hierarchy is usually presented by a pedigree tree where all the ...
- PTA甲级1094 The Largest Generation (25分)
PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...
- 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 ...
- 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 ...
- 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 ...
- PAT 甲级 1094 The Largest Generation
https://pintia.cn/problem-sets/994805342720868352/problems/994805372601090048 A family hierarchy is ...
随机推荐
- day22面向对象
面向对象编程: 1.什么是面向对象 面向过程(编程思想): 过程,解决问题的步骤,流程即第一步做什么,第二步做什么 将复杂问题,拆成若干小问题,按照步骤一一解决,将复杂问题流程化(为其制定固定的实现流 ...
- 用java Graphics生成验证码
以下下是API文档对Graphics的介绍! Graphics 类是所有图形上下文的抽象基类,允许应用程序在组件(已经在各种设备上实现)以及闭屏图像上进行绘制. Graphics 对象封装了 Java ...
- int (*a)[10] 和 int *a[10] 的区别
int *a[10] :指针数组.数组a里存放的是10个int型指针 int (*a)[10] :数组指针.a是指针,指向一个数组.此数组有10个int型元素 int *a[10] 先找到声明符a,然 ...
- Android自动化测试Uiautomator--UiCollection接口简介
这个对象可以理解为一个对象的集合,因为UiSelector描述后得到的有可能是多个满足条件的控件集合,因此可以用来生成UiCollection,继承自UiObject. 用于枚举一个容器的用户界面(U ...
- 关于php使用xpath解析html中文乱码问题
$str2 = '<div id="content">我很好 </div>'; $dom = new DOMDocument(); //load之前强转字符 ...
- 转:深入 AngularUI Router
原文地址:http://www.ng-newsletter.com/posts/angular-ui-router.html ui-router: https://angular-ui.github. ...
- 读CSS DIV网页样式与布局心得体会
一.首先根据网页设计图拆分网页的整体结构 二.在html页面用DIV划分出结构块 三.再根据设计图在各个大<DIV>块中加入对应的小<DIV>块或者段落<P>,表单 ...
- POJ-1696 Space Ant 凸包版花式水过!
Space Ant 明天早上最后一科毛概了,竟然毫无复习之意,沉迷刷题无法自拔~~ 题意:说实 ...
- Unity3D for iOS初级教程:Part 1/3
转自Unity 3d for ios 这篇文章还可以在这里找到 英语 Learn how to use Unity to make a simple 3D iOS game! 这篇教材是来自教程团队成 ...
- 【CCF】棋局评估
博弈论极小极大搜索,记忆化+状压 #include<iostream> #include<cstdio> #include<string> #include< ...