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> ...
随机推荐
- request参数获取的几种方式
经常用到Request.QueryString[""]和Request.Form[""]来获取参数值. 今天照常用,ajax方式向后台传参,先用的Request ...
- 联想THINKPAD E40的快捷键怎么关闭?哪些F1 F2 F3的键我需要用到 但是每次都按FN 太烦人了
1.开机时,按F1进入BIOS,依次选择CONFIG--Keyboard/Mouse,2.在Change to "f1-f12 keys"选项中,更改设置为Legacy或者Defa ...
- swift获取图片路径出错
获取图片路径 用以下方式获取 let path = Bundle.main.path(forResource: "ImageName", ofType: "ImageTy ...
- 【剑指offer】丑数,C++实现
原创博文,转载请注明出处!本题牛客网地址 博客文章索引地址 博客文章中代码的github地址 1. 题目 2. 思路 空间换时间的方法.由于题目要求按序查找丑数,可以采用辅助容器vector按序存储丑 ...
- 全球常用NTP服务器地址及IP列表ntpdate
pool.ntp.org是一组授时服务器虚拟集群,在全球有3000多台服务器,只需要这样写就行了,具体哪台服务器提供服务无需关心. time.windows.com 微软 asia.pool.nt ...
- windows主机与virtualbox虚拟机下的Linux共享网络
环境: 主机:windows7 虚拟机:virtualbox 4.2 虚拟系统:CentOS6.2 需求: 1.虚拟机linux可以共享主机网络上互联网 2.主机.虚拟机互通讯,组成一个虚拟的局域网, ...
- LOJ2421 NOIP2015 信息传递 【tarjan求最小环】
LOJ2421 NOIP2015 信息传递 LINK 题目大意就是给你一个有向图,求最小环 有一个很奇妙的性质叫做每个点只有一条出边 然后我们考虑对每个强联通分量进行考虑 发现每个强联通分量内的边数一 ...
- Visual studio环境中的一些快捷键
VS的快键键 F12(转到定义),那怎么转回定义呢? 转回应该是Ctrl+Shift+8 自动排版:ctrl+E+D
- check sub-string in the string
if "blah" not in somestring: continue
- kong 安装
1. yum 参考信息 https://bintray.com/kong/kong-community-edition-rpm $ sudo yum install epel-release $ su ...