题意:略。

思路:层序遍历;在结点中增加一个数据域表示结点所在的层次。

代码:

#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
struct Node{
    int layer;
    vector<int> child;
};
vector<Node> tree();
]={};
,maxNum=;

void levelOrderTraversal(int root)
{
    queue<Node> q;
    tree[root].layer=;
    q.push(tree[root]);
    while(!q.empty()){
        Node node=q.front();
        q.pop();
        level[node.layer]++;
        if(level[node.layer] > maxNum){
            maxNum=level[node.layer];
            maxLevel=node.layer;
        }
        for(auto it:node.child){
            tree[it].layer=node.layer+;
            q.push(tree[it]);
        }
    }
}

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int id,k,kid;
    ;i<m;i++){
        scanf("%d%d",&id,&k);
        ;j<k;j++){
            scanf("%d",&kid);
            tree[id].child.push_back(kid);
        }
    }
    levelOrderTraversal();
    printf("%d %d\n",maxNum,maxLevel);
    ;
}

1094 The Largest Generation的更多相关文章

  1. PAT 1094 The Largest Generation[bfs][一般]

    1094 The Largest Generation(25 分) A family hierarchy is usually presented by a pedigree tree where a ...

  2. PAT甲级——1094 The Largest Generation (树的遍历)

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

  3. 1094 The Largest Generation ——PAT甲级真题

    1094 The Largest Generation A family hierarchy is usually presented by a pedigree tree where all the ...

  4. PTA甲级1094 The Largest Generation (25分)

    PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...

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

  6. 1094. The Largest Generation (25)

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

  7. PAT 甲级 1094 The Largest Generation

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

  8. PAT 1094. The Largest Generation (层级遍历)

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

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

  10. PAT (Advanced Level) 1094. The Largest Generation (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

随机推荐

  1. LVS模式一:直接路由模式DR(Direct Routing)

    (一)LVS 一.LVS的了解 LVS(Linux Virtual Server)可以理解为一个虚拟服务器系统. Internet的飞速发展,网络带宽的增长,Web服务中越来越多地使用CGI.动态主页 ...

  2. Lodash 浓缩

    Lodash 是个十分有用的工具库,但我们往往只需要其中的一小部分函数.这时,整个 lodash 库就显得十分庞大,我们需要减小 lodash 的体积. cherry-pick 方法 Lodash 官 ...

  3. Vim技能修炼教程(3) - 语法高亮进阶

    语法高亮进阶 首先我们复习一下上节学到的三个命令: * syntax match用于定义正则表达式和规则的对应 * highlight default定义配色方案 * highlight link将正 ...

  4. [Linux] 使用rename批量重命名文件

    例如把所有png文件的后缀改为jpg $ rename 's/png/jpg/' *png

  5. 使用Linq动态排序

    Linq排序很方便,如果能动态创建Expression再排序就更方便了. 正序还是倒序排列 var order = typeof(Enumerable).GetMember(direction == ...

  6. CentOS7 firewalld设置端口

    Centos升级到7之后,发现无法使用iptables控制Linuxs的端口,google之后发现Centos 7使用firewalld代替了原来的iptables.下面记录如何使用firewalld ...

  7. 跳转后全屏,兼容大部分浏览器JavaScript

    <!DOCTYPE html> <html> <head> <title>测试</title> </head> <body ...

  8. BZOJ2565 最长双回文串 【Manacher】

    BZOJ2565 最长双回文串 Description 顺序和逆序读起来完全一样的串叫做回文串.比如acbca是回文串,而abc不是(abc的顺序为"abc",逆序为"c ...

  9. DVD项目

    package sy.com.cn;import java.util.*; public class DvdWorker { public static void main(String[]args) ...

  10. hdfs会出现的一些问题

    实训的第一篇博客献给坑了我的hdfs…… 由于电脑的原因,突然花屏,虚拟机来不及挂起.之后发现50070端口进不去,查看jps进程发现没有namenode 先用stop-all.sh命令再start还 ...