题意:

输入两个正整数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. 1、Two Sum

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  2. 期货homes平台以及仿ctp接口

    实盘账户或者模拟账户可以下挂多个子账户 子账户也可以是homes母账户,理论上可以一层一层套下去. 所有交易细节全部保存,收盘定时结算. 功能很强大,并且还有很多拓展空间. 连接homes平台,需要用 ...

  3. JVM&GC详解

    1.JVM简介 JVM是java的核心和基础,在java编译器和os平台之间的虚拟处理器.它是一种利用软件方法实现的抽象的计算机基于下层的操作系统和硬件平台,可以在上面执行java的字节码程序. ja ...

  4. python3练习100题——011

    原题链接:http://www.runoob.com/python/python-exercise-example11.html 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔 ...

  5. 整理收集的一些常用java工具类

    1.json转换工具 package com.taotao.utils; import java.util.List; import com.fasterxml.jackson.core.JsonPr ...

  6. python中乱码怎么由来与解决方法

    前言曾几何时 Python 中文乱码的问题困扰了我很多很多年,每次出现中文乱码都要去网上搜索答案,虽然解决了当时遇到的问题但下次出现乱码的时候又会懵逼,究其原因还是知其然不知其所以然.现在有的小伙伴为 ...

  7. linux做免密登录,成功分发公钥后登录主机依旧需要输入密码的问题解决

    问题描述 在主机A上用ssh-keygen生成密钥对后,用ssh-copy-id命令将公钥成功copy到主机B上后,测试从A免密登录B,但是依旧需要输入主机B的密码后才能登录. 出现此错误的原因 如果 ...

  8. php 基础系列之 php快速入门

    ·插补操作 将简单变量写入一个由双引号引用的字符串中,就叫插补操作.例如: $test = 'xx'; echo "你好:$test"; 注意:插补操作只是双引号引用字符串的特性. ...

  9. Bayer Pattern

    在刚加入工作的时候,听到最多的就是RGGB Bayer Pattern.在之前的接触中,一直默认一张图片的每个像素点有RGB三个分量,那“RGGB Bayer Pattern”究竟是什么意思.在网上查 ...

  10. jquery使用ajax实现实时刷新,轮询

    来自:https://blog.csdn.net/qq_25406669/article/details/78343082 var isLoaded = false; function reqs() ...