题意:

输入两个正整数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. 服务遇到的问题 Linux

    1.vnc配置: https://www.cnblogs.com/leolzi/p/9907856.html 2.遇到的问题,linux重启后不能链接的问题 rabbitmq 服务启动问题 [bf@l ...

  2. normalization, standardization and regularization

    Normalization Normalization refers to rescaling real valued numeric attributes into the range 0 and ...

  3. 【原】librtmp源码详解

    “悟已往之不谏,知来者之可追”.后悔做了这么久的直播,却不曾理解rtmp协议的实现原理,现在意识到了这个问题,特此补救.同时谨以此文纪念曾经的雷霄骅同学,感谢他对音视频领域做出的卓越贡献和引领. 1. ...

  4. (转)git学习教程

    转自:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

  5. NW.js桌面应用开发(一)

    NWjs中文网 Electron中文网 一些需要了解的历史与特性,其实就是 NW.js 和 Electron的争议,建议还是亲自阅读一下各自的官网说明 1.下载SDK版工具 从淘宝NPM镜像下载,速度 ...

  6. python面试的100题(5)

    5.现有字典 d= {'a':24,'g':52,'i':12,'k':33}请按value值进行排序? sorted(d.items(),key=lambda x:x[1]) sorted函数 对由 ...

  7. django初步了解(一)

    安装django pip3 install django==版本号 创建一个djangp项目 django-admin startproject 项目名 目录介绍: 运行django项目: pytho ...

  8. js替换所有匹配字符

    js没有replaceAll,所以用正则表达式查找所有匹配项("g"), .replace(new RegExp("\\.", "g"), ...

  9. OPGL+VS2017+GLFW+GLEW配置详细步骤

    OPGL+VS2017+GLFW+GLEW配置详细步骤: https://blog.csdn.net/weixin_40921421/article/details/80211813 原博客地址:ht ...

  10. 2019牛客多校第二场F Partition problem 暴力+复杂度计算+优化

    Partition problem 暴力+复杂度计算+优化 题意 2n个人分成两组.给出一个矩阵,如果ab两个在同一个阵营,那么就可以得到值\(v_{ab}\)求如何分可以取得最大值 (n<14 ...