题意:略。

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

代码:

#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. jquery中ajax跨域的写法

    由于JS同源策略的影响,因此js只能访问同域名下的文档.因此要实现跨域,一般有以下几个方法: 一.处理跨域的方式: 1.代理 2.XHR2 HTML5中提供的XMLHTTPREQUEST Level2 ...

  2. python 获取当前时间(关于time()时间问题的重要补充)

    python 获取当前时间   我有的时候写程序要用到当前时间,我就想用python去取当前的时间,虽然不是很难,但是老是忘记,用一次丢一次,为了能够更好的记住,我今天特意写下python 当前时间这 ...

  3. 【LeetCode 88_数组】Merge Sorted Array

    void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) { ; ; ; &&a ...

  4. 2018.11 企业战略课堂笔记2 SWOT-4C战略

    1因素列表 2分析过程 :重要的是逻辑推理过程 3  4C战略

  5. L153

    警言是指传达一般真理或某种言论的短小句子.An aphorism is a short witty sentence which expresses a general truth or commen ...

  6. Data truncated for column

    数据类型不合法造成的.检查插入的数据.

  7. [置顶] Isolation Forest算法原理详解

    本文只介绍原论文中的 Isolation Forest 孤立点检测算法的原理,实际的代码实现详解请参照我的另一篇博客:Isolation Forest算法实现详解. 或者读者可以到我的GitHub上去 ...

  8. python caffe 在师兄的代码上修改成自己风格的代码

    首先,感谢师兄的帮助.师兄的代码封装成类,流畅精美,容易调试.我的代码是堆积成的,被师兄嘲笑说写脚本.好吧!我的代码只有我懂,哈哈! 希望以后代码能写得工整点.现在还是让我先懂.这里,我做了一个简单的 ...

  9. 【Python】下载图片

    import requests import bs4 import urllib.request import urllib import os hdr = {'User-Agent': 'Mozil ...

  10. 观后感 - 从MVC到前后端分离

    今天读了篇文章 从MVC到前后端分离,讲了 前后端分离的 JAVA实现,读了前面几段就发现 自己 就有这种想法,蛮有意思的,打算研究下在PHP上的实现和应用