PAT (Advanced Level) 1094. The Largest Generation (25)

Posted Fighting Heart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT (Advanced Level) 1094. The Largest Generation (25)相关的知识,希望对你有一定的参考价值。

简单DFS。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

const int maxn=200;
int n,m;
vector<int>g[maxn];
int ans[maxn];

void dfs(int x,int dep)
{
    ans[dep]++;
    for(int i=0;i<g[x].size();i++)
        dfs(g[x][i],dep+1);
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int id; scanf("%d",&id);
        int num; scanf("%d",&num);
        while(num--)
        {
            int x; scanf("%d",&x);
            g[id].push_back(x);
        }
    }
    memset(ans,0,sizeof ans);
    dfs(1,0);

    int Max=0;
    for(int i=0;i<=n;i++) Max=max(ans[i],Max);
    for(int i=0;i<=n;i++)
    {
        if(ans[i]==Max)
        {
            printf("%d %d\n",ans[i],i+1);
            break;
        }
    }
    return 0;
}

 

以上是关于PAT (Advanced Level) 1094. The Largest Generation (25)的主要内容,如果未能解决你的问题,请参考以下文章

PAT (Advanced Level) 1094. The Largest Generation (25)

PAT Advanced 1094 The Largest Generation (25) [BFS,DFS,树的遍历]

PAT (Advanced Level) 1025. PAT Ranking (25)

PAT Advanced Level 1044

PAT Advanced Level 1043

PAT Advanced Level 1079