简单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. android 动态string

    android开发过程之中,动态的插入string内容时候使用, 例如, <string name="time">当前时间:<xliff:g id="p ...

  2. mysql sql语句大全(转载)

      1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- 创建 ...

  3. SQL函数学习(三):convert()函数

    格式:CONVERT(data_type,expression[,style])说明:此样式一般在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,c ...

  4. android开发技巧

    1 Android去掉listView,gridView等系统自带阴影 当我们使用listView的时候,拉到顶,或是拉到底部的时候,我们会发现有系统自带的阴影效果出现,不同手机出现的颜色可能还会不一 ...

  5. hadoop文件系统浅析

    1.什么是分布式文件系统? 管理网络中跨多台计算机存储的文件系统称为分布式文件系统. 2.为什么需要分布式文件系统了? 原因很简单,当数据集的大小超过一台独立物理计算机的存储能力时候,就有必要对它进行 ...

  6. SourceTree基础

    克隆(clone):从远程仓库URL加载创建一个与远程仓库一样的本地仓库 提交(commit):将暂存文件上传到本地仓库(我们在Finder中对本地仓库做修改后一般都得先提交一次,再推送) 检出(ch ...

  7. C语言_用if```else语句解决奖金发放问题

    #include<stdio.h> #include<stdlib.h> /*企业发放的奖金根据利润提成,发放规则如下: 利润(I)低于或等于10万元时,奖金可提10%: 利润 ...

  8. 面向对象的特性-为String类型的变量扩展一个replaceAll()函数

    ———————————————————————————— <script type="text/javascript">                    //按钮 ...

  9. hdu_2446_Shell Pyramid(数学,二分)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2446 题意:题面很大,有用的就那么几句,意思就是用自然数来堆它画的那个金字塔,比如第一个金字塔的第一个 ...

  10. LeetCode OJ 236. Lowest Common Ancestor of a Binary Tree

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...