1094. The Largest Generation (25)-(dfs,树的遍历,统计每层的节点数)
题目很简单,就是统计一下每层的节点数,输出节点数最多的个数和对应的层数即可。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h> using namespace std;
const int maxn=;
int num[maxn];
int head[maxn];
int tot; struct Edge{
int to;
int next;
}edge[maxn]; void init(){
memset(head,-,sizeof(head));
tot=;
}
void add(int x,int y){
edge[tot].next=head[x];
edge[tot].to=y;
head[x]=tot++;
}
void dfs(int root, int layer){
num[layer]++;
for(int i=head[root];i!=-;i=edge[i].next){
int v=edge[i].to;
dfs(v,layer+);
}
}
int main()
{
int n,m,k,a,b;
init();
scanf("%d %d",&n,&m);
for(int i=;i<=m;i++){
scanf("%d %d",&a,&k);
for(int j=;j<k;j++){
scanf("%d",&b);
add(a,b);
}
}
memset(num,,sizeof(num));
dfs(,);
int maximum=,layer;
for(int i=;i<maxn;i++){
if(num[i]>maximum){
maximum=num[i];
layer=i;
}
}
printf("%d %d\n",maximum,layer);
return ;
}
1094. The Largest Generation (25)-(dfs,树的遍历,统计每层的节点数)的更多相关文章
- 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 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) 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甲级】1094 The Largest Generation (25 分)(DFS)
题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...
- 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 (Advanced Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT练习——1094 The Largest Generation (25 point(s))
题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...
- PAT甲级——1094 The Largest Generation (树的遍历)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...
- pat1094. The Largest Generation (25)
1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
随机推荐
- DOS 总结
shutdown -s -t 30 指定在30秒之后自动关闭计算机. + L 返回登录页面 netstat 最近访问IP Regedit 打开注册表
- Hadoop HBase概念学习系列之HBase里的客户端和HBase集群建立连接(详细)(十四)
需要遵循以下步骤: 1.客户端和Zookeeper集群建立连接.在这之前客户端需要获得一些信息(可以从HBase配置文件中读取或是直接指定).客户端从Zookeeper集群中读取-ROOT-表的位置信 ...
- 题解 P1312 【Mayan游戏】
题面 过长已遮挡 题意 体面已经陈述题意(这题没有考语文阅读理解) 题解 ** 我还记得我曾经给自己找的锅,给某些人讲课的时候说过一句话:体面越长的题,越简单.** 这句话没有错,我会用接下来解决这道 ...
- oracle备份与恢复
Oracle数据库有三种标准的备份方法,它们分别是导出/导入(EXP/IMP).热备份和冷备份.导出备件是一种逻辑备份,冷备份和热备份是物理备份. 导出/导入(Export/Import) 利用Exp ...
- XSS详解
什么是XSS(跨站脚本攻击) XSS又叫CSS (Cross Site Script) ,跨站脚本攻击.它指的是恶意攻击者往Web页面里插入恶意html代码或者javascript代码,当用户浏览该页 ...
- Universal-Image-Loader源码分析(二)——载入图片的过程分析
之前的文章,在上面建立完config之后,UIl通过ImageLoader.getInstance().init(config.build());来初始化ImageLoader对象,之后就可以用Ima ...
- mysql主从复制亲测,以及注意事项
本人亲测,windows作为mysql主服务器,linux作为从服务器,使用两个linux配置步骤都一样,测一遍而已:区别配置文件在于windwos是my.ini.linux在/etc/my.cof ...
- Scala学习之路 (七)Scala的柯里化及其应用
一.概念 柯里化(currying, 以逻辑学家Haskell Brooks Curry的名字命名)指的是将原来接受两个参数的函数变成新的接受一个参数的函数的过程.新的函数返回一个以原有第二个参数作为 ...
- 1 TCP/IP通信
重点参考长链接http://blog.csdn.net/fengyuzhengfan/article/details/38830115 http://blog.csdn.net/Jsagacity/a ...
- ethereum/EIPs-170 Contract code size limit
eip title author type category status created 170 Contract code size limit Vitalik Buterin Standards ...