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

#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. 有关java编辑器myeclipse编辑网站的一些设置(个人习惯)

    一.界面显示设置 首先进入一个新的空间,里面的设置肯定都是默认的.点击上方导航栏的window-Perferences-Appearance可以去进行设置界面的显示,Theme中可以选择windows ...

  2. 卷积神经网络入门:LeNet5(手写体数字识别)详解

    第一张图包括8层LeNet5卷积神经网络的结构图,以及其中最复杂的一层S2到C3的结构处理示意图. 第二张图及第三张图是用tensorflow重写LeNet5网络及其注释. 这是原始的LeNet5网络 ...

  3. VS 代码整理插件推荐:CodeMaid

    一直在用,觉得很不错,其他插件基本上不用了,所以拿来记录并分享一下.CodeMaid 说明文档CodeMaid 下载安装不用说明了,使用看说明文档就好. CodeMaid和ReSharp类似,开源且免 ...

  4. PyQt5--QSlide

    # -*- coding:utf-8 -*- ''' Created on Sep 20, 2018 @author: SaShuangYiBing Comment: ''' import sys f ...

  5. python第二十九课——文件读写(复制文件)

    自定义函数:实现文件复制操作有形参(2个) 没有返回值相似版(不用) def copyFile(src,dest): #1.打开两个文件:1个关联读操作,1个关联写操作 fr=open(src,'rb ...

  6. 网络嗅探与欺骗(第一二部分)非平台——P201421410029

    中国人民公安大学 Chinese people’ public security university 网络对抗技术 实验报告   实验二 网络嗅探与欺骗     学生姓名 李政浩 年级 2014 区 ...

  7. python之生成随机测验试卷

    自己又开始懒散的态度生活,所以几乎有两个月没有更博了. 项目:美国各州首府地理考试,为防止作弊,35份试卷,50道题随机次序,生成独一无二的试卷. 基本想法: 1.将各州首府的地方和首府写入列表,以K ...

  8. Python3使用tkinter编写GUI程序

    目录 @(Python3中tkinter写的HTTP测试工具代码支持正则表达式和XPATH) 程序非常简单,暂时只支持GET方法,使用内置库tkinter编写GUI窗口,在Mac下运行效果图如下,wi ...

  9. JS时间轴效果(类似于qq空间时间轴效果)

    在上一家公司写了一个时间轴效果,今天整理了下,感觉有必要写一篇博客出来 给大家分享分享 当然代码还有很多不足的地方,希望大家多指点指点下,此效果类似于QQ空间或者人人网空间时间轴效果,当时也是为了需求 ...

  10. Python2.7-canlendar

    calendar模块的主要功能是针对万年历.星期几的,此外模块内还有方便的判断闰年.获取月份名.星期名的方法 1.模块的类 1.1.calendar.Calendar([firstweekday]) ...