PAT (Advanced Level) 1094. The Largest Generation (25)
简单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)的更多相关文章
- 【PAT甲级】1094 The Largest Generation (25 分)(DFS)
题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...
- 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 ...
- 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 ...
- 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 (25 point(s))
题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...
- 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, ...
- PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1110. Complete Binary Tree (25)
判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...
随机推荐
- .Net_把文件数据添加到数据库中(面试题)
一个文本文件含有如下内容: 4580616022644994|3000|赵涛 4580616022645017|6000|张屹 4580616022645090|3200|郑欣夏 上述文件每行为一个转 ...
- winsock编程WSAAsyncSelect模型
winsock编程WSAAsyncSelect模型 WSAAsyncSelect模型也称异步选择模型,其核心函数是WSAAsyncSelect.它可以用来在一个socket上接收以windows消息为 ...
- android 常用
1:常用之动画(View Animation,Drawable Animation,Property Animation) http://blog.csdn.net/huxueyan521/artic ...
- 第三十节,正则表达式re模块
正则表达式 正则表达式本身是一种小型的.高度专业化的编程语言,而在python中,通过内嵌集成re模块,程序员们可以直接调用来实现正则匹配.正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引 ...
- DOM操作-引用同级的元素
代码: ———————————————————————————————— <script type="text/javascript"> //获取 ...
- JPG、PNG和GIF图片的基本原理及优化方法
一提到图片,我们就不得不从位图开始说起,位图图像(bitmap),也称为点阵图像或绘制图像,是由称作像素(图片元素)的单个点组成的.这些点可以进行不同的排列和染色以构成一副图片.当放大位图时,可以看见 ...
- a标签无跳转的死链接
<a href="#" onclick="return false;">link1</a> <a href="javas ...
- Ansible1:简介与基本安装【转】
Ansible是一个综合的强大的管理工具,他可以对多台主机安装操作系统,并为这些主机安装不同的应用程序,也可以通知指挥这些主机完成不同的任务.查看多台主机的各种信息的状态等,ansible都可以通过模 ...
- network: 思科-华为光模块
思科-华为光模块的分类比较 摘要:本文介绍:思科GLC-SX-MM,GLC-LH-SM光模块等产品参数与图片,华为光模块的型号与分类等知识. 光模块分类与介绍 一.思科厂家 1.多模光模块 型号: ...
- doclint in jdk8
http://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html Turning off doclint in JDK 8 ...