题意:略。

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

代码:

#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. .net 获取客户端Ip地址

    Request.ServerVariables["REMOTE_ADDR"]来取得客户端的IP地址,但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的IP地址,而不是真正 ...

  2. Shell 命令行批量处理图片文件名

    Shell 命令行批量处理图片文件名 从网上下载了一堆图片,有的是*.jpg的,有的是*.jpeg的.并且文件名有长有短,很是糟心.因此,我想把这些文件给全部整理好,当然是用shell来处理啦! 说干 ...

  3. linux环境搭建记录

    第一次搭建环境,部署服务,在此记录一下过程 1.项目用到的hosts设置好 2.mkdir data,在data文件夹下建server,log,soft,resource路径,上载jdk.zip到so ...

  4. SQL Server Profiler 跟踪远程服务器的语句

    同事测试软件报错,想连Ta的数据库跟踪下语句,结果提示:      对比了下自己的探查器设置,勾选几个事件就可以了:

  5. Javascrpt 速成篇】 三:js事件处理

    ie和chrome,firefox的事件处理,除了函数名字不同,基本大同小异.这样就已chrome为主了,对ie有兴趣的自己去百度.jquery已经处理不同浏览器兼容性问题,推荐使用. 事件处理有两种 ...

  6. MySQL性能指标计算方式

    -- 生成报告文件到/tmp目录中 tee /tmp/mysql_performance_stat.txt -- 统计性能指标前先开启下列参数,该参数使用IS数据库来存放数据库信息,由于使用PS库存放 ...

  7. hdu1575 Tr A 矩阵初识

    A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973.  Input数据的第一行是一个T,表示有T组数据. 每组数据的第一行有n(2 <= n <= ...

  8. redis整合异常总结

    问题:org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field ' ...

  9. ruby 的数组操作

    转自:http://fujinbing.iteye.com/blog/1126232 1. & [ 1, 1, 3, 5 ] & [ 1, 2, 3 ] # => [1, 3] ...

  10. 《DSP using MATLAB》第7章开始 Example7.1

    FIR低通滤波器的设计要求示意图: