1094 The Largest Generation
题意:略。
思路:层序遍历;在结点中增加一个数据域表示结点所在的层次。
代码:
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
struct Node{
int layer;
vector<int> child;
};
vector<Node> tree();
]={};
,maxNum=;
void levelOrderTraversal(int root)
{
queue<Node> q;
tree[root].layer=;
q.push(tree[root]);
while(!q.empty()){
Node node=q.front();
q.pop();
level[node.layer]++;
if(level[node.layer] > maxNum){
maxNum=level[node.layer];
maxLevel=node.layer;
}
for(auto it:node.child){
tree[it].layer=node.layer+;
q.push(tree[it]);
}
}
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int id,k,kid;
;i<m;i++){
scanf("%d%d",&id,&k);
;j<k;j++){
scanf("%d",&kid);
tree[id].child.push_back(kid);
}
}
levelOrderTraversal();
printf("%d %d\n",maxNum,maxLevel);
;
}
1094 The Largest Generation的更多相关文章
- 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 (树的遍历)
本文同步发布在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 ...
- 1094. The Largest Generation (25)
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 ...
- 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 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 (Advanced Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- VirtualBox安装Redhat9.0
1.准备软件 虚拟机:VirtualBox-4.3.8-92456-Win.exe RedHat:shrike-i386-disc1.iso shrike-i386-disc2.iso ...
- New Concept English three (24)
33 72 We often read in novels how a seemingly respectable person or family has some terrible secret ...
- 迭代器、foreach循环、泛型集合
集合的迭代 语法:Iterator<Object> it=集合.iterator(); while(it.hasNext()){ Object obj=it.next(); } is.ha ...
- React状态管理之redux
其实和vue对应的vuex都是差不多的东西,这里稍微提一下(安装Redux略过): import { createStore, combineReducers, applyMiddleware } f ...
- React-Native进阶_2.加载指示动画 ActivityIndicator
在安卓原始 App中使用的加载框 ProgressBar 在React -Native 中也是有相对应的视图,叫做ActivityIndicator,对应ios 中React-Native 提供的是 ...
- MPAndroidChart Wiki(译文)~Part 3
13. 图例 默认情况下,所有的图表都支持图例并且会自动生成.给图表设置完数据之后,图例会被绘制出来.图例通常由多个条目组成,每个条目由标签形式/形状表示. 自动生成的图例包含的条目数取决于不同颜色的 ...
- ET之快递测试法学习感悟20140922
快递测试法,是从ET学习中了解到的一种测试方法,顾名思义就是数据类似于那些通过联邦快递系统在这个星球上被不断移动的包裹一样,在软件中也不断的流动.数据从被输入后就开始了它的生命周期,先被存储在内部变量 ...
- Js/Jquery获取网页屏幕可见区域高度
获取浏览器窗口的可视区域高度和宽度,滚动条高度有需要的朋友可参考一下. 1 document.body.clientWidth ==> BODY对象宽度 2 document.body.clie ...
- 上传IOS项目和版本更新流程图
上传IOS项目和版本更新流程图 必备IDP证书和distribution证书(第一个证书是真机部署测试时用到的,后者证书是发布时需要用到的,缺一不可). 我就说说接下来应该做的流程.在你保证拥有以上两 ...
- .pyc和.pyo文件有何用
百度知道:http://zhidao.baidu.com/link?url=_tFP1xglFnoEBObWtIArI3b3Ft0PQowx5m5ruIaX3mFIAFVr7vX45Lfb0geCjA ...