1094. The Largest Generation (25)

简介: #include #include using namespace std;vector v[100];int maxdepth = 0, level[100] = {0};bool visited[100] = ...
#include <iostream>
#include <vector>
using namespace std;
vector<int> v[100];
int maxdepth = 0, level[100] = {0};
bool visited[100] = {false};

void dfs(int index, int depth){
    if(!visited[index]) level[depth]++;
    visited[index] = true;
    if(v[index].size() == 0){
        if(depth > maxdepth) maxdepth = depth;
        return;
    }
    for (int i = 0; i < v[index].size(); i++)
        dfs(v[index][i], depth + 1);
}

int main(){
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int f, k;
        cin >> f >> k;
        for (int j = 0; j < k; j++) {
            int t;
            cin >> t;
            v[f].push_back(t);
        }
    }
    dfs(1, 0);
    int maxnum = 0, maxg = 0;
    for (int i = 0; i <= maxdepth; i++) {
        if(level[i] > maxnum){ maxnum = level[i]; maxg = i + 1;}
    }
    cout << maxnum << ' ' << maxg << endl;

    return 0;
}
目录
相关文章
|
8月前
|
机器学习/深度学习 数据挖掘 Python
[Bart]论文实现:Denoising Sequence-to-Sequence Pre-training for Natural Language Generation...
[Bart]论文实现:Denoising Sequence-to-Sequence Pre-training for Natural Language Generation...
65 0
|
存储
LeetCode 329. Longest Increasing Path in a Matrix
给定一个整数矩阵,找出最长递增路径的长度。 对于每个单元格,你可以往上,下,左,右四个方向移动。 你不能在对角线方向上移动或移动到边界外(即不允许环绕)。
85 0
LeetCode 329. Longest Increasing Path in a Matrix
|
算法
LeetCode 300. Longest Increasing Subsequence
给定一个无序的整数数组,找到其中最长上升子序列的长度。
60 0
LeetCode 300. Longest Increasing Subsequence
|
机器学习/深度学习 自然语言处理 搜索推荐
Re25:读论文 Lecut+JOTR Incorporating Retrieval Information into the Truncation of Ranking Lists in the
Re25:读论文 Lecut+JOTR Incorporating Retrieval Information into the Truncation of Ranking Lists in the
Re25:读论文 Lecut+JOTR Incorporating Retrieval Information into the Truncation of Ranking Lists in the
【1094】The Largest Generation (25 分)
【1094】The Largest Generation (25 分) 【1094】The Largest Generation (25 分)
80 0
|
SQL 移动开发 算法
New Dynamic Programming Algorithm for the Generation of Optimal Bushy Join Trees
MySQL无疑是现在开源关系型数据库系统的霸主,在DBEngine的最新排名中仍然稳居第2位,与第3位SQL Server的积分差距并不算小,可以说是最受欢迎,使用度最高的数据库系统,这一点看看有多少新型数据库要兼容MySQL的协议和语法就知道了。
349 0
New Dynamic Programming Algorithm for the Generation of Optimal Bushy Join Trees
|
算法 C#
算法题丨Longest Consecutive Sequence
描述 Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
1126 0