题意:

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

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
vector<int>v[];
int ans[];
void dfs(int x,int storey){
++ans[storey];
for(auto it:v[x])
dfs(it,storey+);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
for(int i=;i<=m;++i){
int x;
cin>>x;
int num;
cin>>num;
for(int j=;j<=num;++j){
int y;
cin>>y;
v[x].push_back(y);
}
}
dfs(,);
int mx=,pos=;
for(int i=;i<=n;++i)
if(ans[i]>mx){
mx=ans[i];
pos=i;
}
cout<<mx<<" "<<pos;
return ;
}

【PAT甲级】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甲级——1094 The Largest Generation (树的遍历)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...

  3. PAT 甲级 1094 The Largest Generation

    https://pintia.cn/problem-sets/994805342720868352/problems/994805372601090048 A family hierarchy is ...

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

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

  6. 1094. The Largest Generation (25)-(dfs,树的遍历,统计每层的节点数)

    题目很简单,就是统计一下每层的节点数,输出节点数最多的个数和对应的层数即可. #include <iostream> #include <cstdio> #include &l ...

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

  8. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

  9. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

随机推荐

  1. centos7解压压缩zip文件

    一.安装支持ZIP的工具 yum install -y unzip zip 二.解压zip文件 unzip 文件名.zip 二. 压缩一个zip文件 zip 文件名.zip 文件夹名称或文件名称

  2. Dimensionality and high dimensional data: definition, examples, curse of..

    Dimensionality in statistics refers to how many attributes a dataset has. For example, healthcare da ...

  3. C++——一维数组

    6.数组 指针与字符串 6.1 数组 数组是具有一定顺序关系的若干相同类型变量的集合体,组成数组的变量成为数组的元素.数组属于构造类型. 一维数组的声明: 类型说明符 数组名[常量表达式],若int ...

  4. please execute the cleanup command

    解决方法: (1)用dos命令进入项目文件夹,运行svn cleanup:不要直接右键点击找cleanup选项 (2)到上一层目录去cleanup试下,或者到.svn文件夹下(隐藏的)找到所有的loc ...

  5. [转]Jarvis OJ- [XMAN]level2/3_x64-Writeup

    学弟写的挺好的,我就直接转过来了 原文链接:http://www.cnblogs.com/ZHijack/p/7940686.html 两道64位栈溢出,思路和之前的32位溢出基本一致,所以放在一起 ...

  6. lvm磁盘扩容

    LVM实现新挂载磁盘扩容到原有目录 #查看磁盘 fdisk -l #创建pv pvcreate /dev/sdb [root@VM-67-49 ~]# pvcreate /dev/sdb Physic ...

  7. 测试理论 - Test Double

    概述 简述 test double mock, fake 之类的东西 背景 最近在看 google 软件测试之道 妈的 13 年的老书了 书里有提到 mock, fake, stub 刚好, 我又不太 ...

  8. go基础_定时器

    每间隔5s打印一句hello // time_ticker package main import ( "fmt" "time" ) func main() { ...

  9. Python的深拷贝、浅拷贝

    浅拷贝 定义:浅拷贝只是对另外一个变量的内存地址的拷贝,这两个变量指向同一个内存地址的变量值. 浅拷贝的特点: 公用一个值: 这两个变量的内存地址一样: 对其中一个变量的值改变,另外一个变量的值也会改 ...

  10. think PHP5中,模板、控制器、JavaScript的url跳转重定向方法

    php控制器中的跳转: 1, header()函数是PHP中进行页面跳转的一种十分简单的方法.主要功能是将HTTP协议标头(header)输出到浏览器. header("Location: ...