题意:略。

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

代码:

#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. this指针逃逸问题

    this指针逃逸是指在构造函数返回之前,其他线程已经就持有了该对象的应用,产生的结果自然和预期可能会产生差异.常见的this指针逃逸,在并发编程实战一书中,作者指出:在构造函数中注册事件监听,在构造函 ...

  2. Linux:history命令详解

      Linux下History命令 主要用于显示历史指令记录内容, 下达历史纪录中的指令 . 语法 history [n] history [-c] history [-raw] histfiles ...

  3. c++多线程编程:实现标准库accumulate函数的并行计算版本

    今天使用c++实现了标准库头文件<numeric>中的accumulate函数的并行计算版本,代码如下,注释写的比较详细,仅对其中几点进行描述: ①该实现假定不发生任何异常,故没有对可能产 ...

  4. Vim技能修炼教程(16) - 浮点数计算函数

    浮点数计算函数 这一节的所有函数,只有在vim编译时支持了+float时才有效. 三角函数 sin() : sine正弦函数 cos() : cosine余弦函数 tan() : tangent正切函 ...

  5. angular 动态修改 ng-bind-html

  6. openssl编译出错解决

    tar -jxvf trafficserver-3.0.2.tar.bz2 ./configure --prefix=/usr/install/trafficserver --with-user=ca ...

  7. [pandas] SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame

    转载自https://blog.csdn.net/blackyuanc/article/details/77892784 问题场景:       在读取CSV文件后,在新增一个特征列并根据已有特征修改 ...

  8. C的文件操作函数

    fgetc(FILE *)意为从文件指针stream指向的文件中读取一个字符,读取一个字节后,光标位置后移一个字节fputc(char,FILE*)将字符ch写到文件指针fp所指向的文件的当前写指针的 ...

  9. Django项目部署(阿里云)(2)--扩展

    新博客地址:http://muker.net/django-server-two.html 前面的只是最简单的部署,真实情况总是更复杂一点实际流程大概是这么操作的(我这种菜鸟的想法):本地写代码-&g ...

  10. HDU - 6172:Array Challenge (BM线性递推)

    题意:给出,三个函数,h,b,a,然后T次询问,每次给出n,求sqrt(an); 思路:不会推,但是感觉a应该是线性的,这个时候我们就可以用BM线性递推,自己求出前几项,然后放到模板里,就可以求了. ...