题意:略。

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

代码:

#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. nodejs之log4js日志记录模块简单配置使用

    在我的一个node express项目中,使用了log4js来生成日志并且保存到文件里,生成的文件如下: 文件名字叫:access.log 如果在配置log4js的时候允许了同时存在多个备份log文件 ...

  2. 从userAgent判断浏览器是什么(chorme ie 火狐)浏览器类型检测、浏览器检测

    一.正确的方法: 通过navigator对象的userAgent属性来判断, 主要是判断userAgent 的信息里是否含有以下字段信息: js代码(非完整版) /************ navig ...

  3. JBPM4入门——1.jbpm简要介绍

    本博文只是简要对JBPM4进行介绍,如需更详细内容请自行google 链接: JBPM入门系列文章: JBPM4入门——1.jbpm简要介绍 JBPM4入门——2.在eclipse中安装绘制jbpm流 ...

  4. L165

    New evidence of how the Norse became long-distance marinersAccording to the saga of Erik the Red, “s ...

  5. Buildroot 指定内核版本

    /******************************************************************************** * Buildroot 指定内核版本 ...

  6. LeetCode - Course Schedule 解题报告

    以前从来没有写过解题报告,只是看到大肥羊河delta写过不少.最近想把写博客的节奏给带起来,所以就挑一个比较容易的题目练练手. 原题链接 https://leetcode.com/problems/c ...

  7. 可能是 BJOI2019 Day1 题解?

    T1 给一个有空白字符的串 $S$,和若干模板串 $X_i$,初始 $Ans = 1$,每当一个模板串在 $S$ 中作为子串出现时,$Ans$ 会乘以 $X_i$ 的权值 $Val_i$,然后如果 $ ...

  8. C的动态链表建立

    运用到的函数为: 动态内存分配函数malloc()              比如:char *name=(char *)malloc(20);  相当与c++的new关键字 动态内存释放函数free ...

  9. 报错【Expression user.achievement is undefined on 】

  10. new Date()相关获取当月天数和当月第一天

    var  myDate = new Date(); //获取本月第一天周几 var monthFirst = new Date(myDate.getFullYear(), parseInt(myDat ...