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 ...
随机推荐
- erlang四大behaviour之一gen_server
来源:http://www.cnblogs.com/puputu/articles/1701017.html erlang程序设计里面有个设计原则就是把你的进程构造成树,把共用代码提出来,特定功能 ...
- MATLAB将变量存储到EXCEL
代码如下: d = {'Time','Temperature'; 12,98; 13,99; 14,97}; xlswrite('testdata2.xls', d, 1, 'E1') 运行如下:
- ural 1353. Milliard Vasya's Function(dp)
1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning ma ...
- submit提交表单后,不刷新当前页面
<form method="get" target="test" action="a.html"> <input type ...
- dist-upgrade
http://www.linuxserve.com/2015/06/how-to-enable-automatic-login-on-debian.html http://www.cyberciti. ...
- lepus监控OS配置
Lepus通过snmp协议进行对操作系统数据采集,因此需要在监控机和被监控机开启snmp服务 snmp协议:简单网络管理协议(SNMP,Simple Network Management Protoc ...
- javascript 深入浅出 (未完成4-17)
慕课网javascript总结 课程地址 课程大纲: 一.数据类型 二.表达式和运算符 三.语句 四.对象 五.数组 六.函数 七.this 八.闭包和作用域 九.OOP 十.正则与模式匹配 ---- ...
- 10- python 网络爬虫分析
Python 网络爬虫简单分析 import urllib2 response = urllib2.urlopen("http://www.baidu.com") print re ...
- android 实践项目
电子词典 http://files.cnblogs.com/blogLYF/lyf_danci.apk
- hadoop文件系统浅析
1.什么是分布式文件系统? 管理网络中跨多台计算机存储的文件系统称为分布式文件系统. 2.为什么需要分布式文件系统了? 原因很简单,当数据集的大小超过一台独立物理计算机的存储能力时候,就有必要对它进行 ...