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> ...
随机推荐
- QT出现 Cannot create children for a parent that is in a different thread 的解决方法:
timer = new Timer(this);改成 timer = new Timer();就可以了. 因为你timer是属于主线程的,尽量不要在非主线程里创建新的对象并指定其对象为主线程内的对象, ...
- 生产者与消费者的Java实现
首先创建maven工程,需要引入的包: <dependencies> <dependency> <groupId>org.apache.kafka</grou ...
- 2018.11.12 RF debug
1 SG setting 2 Date 3 0-1 4 ASK 5 Power supply 6 SG - filter 7 NRF905- demodulation 8 RX test 9 ...
- L153
警言是指传达一般真理或某种言论的短小句子.An aphorism is a short witty sentence which expresses a general truth or commen ...
- linux配置PHP环境!!(云服务器架设)
首先去阿里云或腾讯云购买主机(腾讯云现在有免费30天的云主机...) 购买好之后选择安装: 点登陆 就可以到linux的操作界面了 进入操作界面 输入root账号密码取得权限之后就可以开始配置环境了 ...
- 缺一个UI设计
这几天弄小程序的界面真的是太艰难了,神呐,请赐我一个UI吧 甚至,在第二种布局下的渐变过渡,都拿笔来计算了TT 还有这个色调的选择,在避免过渡效果突兀的处理上,真的是很费工夫啊: 我谁都不服,就服那些 ...
- Linux基础二(修改ip地址、修改网关、修改DNS服务器、重新启动网络配置)
网络的初始化 .ip地址的修改(临时生效) 使用ifconfig命令 ifconfig 网卡名 ip地址 netmask 子网掩码 [root@localhost /]# ifconfig eth1 ...
- 用sublime server 启动本地服务器(手机访问电脑页面)
安装sublime server 插件包 1.Ctrl + shift + p install package ...
- VUE 入门 01
什么是VUE? 它是构建用户界面的JavaScript框架(让他自动生成js.css.html) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vu ...
- HDU5126 stars【CDQ分治】*
HDU5126 stars Problem Description John loves to see the sky. A day has Q times. Each time John will ...