简单DFS。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std; const int maxn=;
int n,m;
vector<int>g[maxn];
int ans[maxn]; void dfs(int x,int dep)
{
ans[dep]++;
for(int i=;i<g[x].size();i++)
dfs(g[x][i],dep+);
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
int id; scanf("%d",&id);
int num; scanf("%d",&num);
while(num--)
{
int x; scanf("%d",&x);
g[id].push_back(x);
}
}
memset(ans,,sizeof ans);
dfs(,); int Max=;
for(int i=;i<=n;i++) Max=max(ans[i],Max);
for(int i=;i<=n;i++)
{
if(ans[i]==Max)
{
printf("%d %d\n",ans[i],i+);
break;
}
}
return ;
}

PAT (Advanced Level) 1094. The Largest Generation (25)的更多相关文章

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

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

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

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

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

  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练习——1094 The Largest Generation (25 point(s))

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

  7. PAT (Advanced Level) 1007. Maximum Subsequence Sum (25) 经典题

    Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...

  8. PAT (Advanced Level) 1113. Integer Set Partition (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. PAT (Advanced Level) 1110. Complete Binary Tree (25)

    判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...

随机推荐

  1. 带宽 VS CDN (转载)

    并发的影响因素:带宽.web server(含php).static server.数据库 带宽价格: 静态IP企业宽带 5M 10M 50M 100M 200M 盛大云 华东双线 216/月 396 ...

  2. 什么是JDBC?

    JDBC是Java数据库连接(Java DataBase Connectivity)技术的简称,提供连接各种常用数据库的能力! 1.方式一(配置文件实现): <!-- 1. 连接池实例 --&g ...

  3. install font

    哪些字体包含国际音标呢? 在微软的Windows与Office的2000或以上版本中分别带有Lucida Sans Unicode和Arial Unicode MS两种字体(以下分别简称LSU和AUM ...

  4. .net 应用Memcached 缓存 demo(非转载,文件下载地址有效)

    一.准备: Memcaced服务端下载地址: http://files.cnblogs.com/sjns/memcached_en32or64.rar Memcaced 客户端类库:http://fi ...

  5. 您可能无法使用服务器管理器,如果两个线程同时访问 IIS 管理 IIS 的修补程序

    http://support.microsoft.com/kb/946517 如果多线程操作 win2003 iis 失败, 打上这个补丁就好了

  6. 认识cookie与session的区别与应用

    通常我们所说的浏览器自动保存密码,下次不用登陆,网页换皮肤,用户引导,提示一次就不再出现的内容,大部分通过cookie或者session来实现的,在这次制作用户引导中,本人就用到了cookie的内容, ...

  7. MJExtension的使用

    1. Plist → 模型数组 控制器中引用#import "MJExtension.h" 模型数组 = [模型类名 objectArrayWithFilename:@" ...

  8. Petit FatFs

    FatFs is a generic FAT/exFAT file system module for small embedded systems. The FatFs module is writ ...

  9. 浅谈SQL Server 对于内存的管理

    简介 理解SQL Server对于内存的管理是对于SQL Server问题处理和性能调优的基本,本篇文章讲述SQL Server对于内存管理的内存原理. 二级存储(secondary storage) ...

  10. LightOJ 1259 Goldbach`s Conjecture 素数打表

    题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...