题目很简单,就是统计一下每层的节点数,输出节点数最多的个数和对应的层数即可。

#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,树的遍历,统计每层的节点数)的更多相关文章

  1. PTA甲级1094 The Largest Generation (25分)

    PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...

  2. 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 ...

  3. 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 ...

  4. 【PAT甲级】1094 The Largest Generation (25 分)(DFS)

    题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...

  5. 1094. The Largest Generation (25)

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

  6. PAT (Advanced Level) 1094. The Largest Generation (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  7. PAT练习——1094 The Largest Generation (25 point(s))

    题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...

  8. PAT甲级——1094 The Largest Generation (树的遍历)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...

  9. pat1094. The Largest Generation (25)

    1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

随机推荐

  1. yum安装某个包出现冲突的情况

    yum安装是非常方便的,可以自动解决依赖问题,但是有时候我们安装包会出现冲突,这个时候我们就要查找是哪些包与哪些包出现冲突,然后再针对性的解决问题. 一般来说起冲突的包会报出来,主要为两点 1.包与包 ...

  2. Asp.net core 2.0.1 Razor 的使用学习笔记(六)

    Asp.net core 2.0.1 Razor 的使用学习笔记——基本页面的建立 VS这版(vs版本:15.5.6  .net版本:4.7.02558)的Razor页面自动生成就是坑爹货,它自动生成 ...

  3. Eclipse 中怎样自动格式化代码?

    首先 有一个 检查代码风格的工具叫checkstyle,具体怎么下载,请自行百度.. 当你在eclipse安装好 checkstyle后,对于使用google标准的人来说,选择一个项目,右键,点击ch ...

  4. 关于Javascript的des加密

    参考文章:https://www.cnblogs.com/MSMXQ/p/4484348.html 需要先下载CryptoJS文件,然后引入其中的两个文件,可以在github中找到. 直接上代码 &l ...

  5. linux 的常用命令---------第九阶段

    Centos 7 系统启动及相关配置文件(面试题) 1. BIOS 初始化,开始post开机自检(主要检查磁盘.cpu.内存) 2. 加载 MBR 到内存 3. GRUB 阶段(可不说) 4. 加载内 ...

  6. lua-resty-gearman模块

    粘贴一段百度对gearman的解释: Gearman是一个用来把工作委派给其他机器.分布式的调用更适合做某项工作的机器.并发的做某项工作在多个调用间做负载均衡.或用来在调用其它语言的函数的系统. lu ...

  7. 用python2.7.9 写个小程序搜索某个目录下行有某关键字

    # -*- coding: utf-8 -*-import sysreload(sys)sys.setdefaultencoding("utf-8")import os def p ...

  8. Linux内核RPC请求过程

    这篇文章讲讲server端RPC报文的处理流程.server端RPC报文的处理函数是svc_process,这个函数位于net/sunrpc/svc.c中.这个函数须要一个svc_rqst结构的指针作 ...

  9. HUE配置HBase

    HBase的配置 修改配置hue.ini的配置文件 [hbase] hbase_clusters=(Cluster|node1:) hbase_conf_dir=/usr/hbase-0.98.12. ...

  10. Windows Server2003 IIS服务器安全配置整理

    一.系统的安装   1.按照Windows2003安装光盘的提示安装,默认情况下2003没有把IIS6.0安装在系统里面.2.IIS6.0的安装 开始菜单—>控制面板—>添加或删除程序—& ...