A1094-The Largest Generation

BFS,DFS都可,但是BFS要记录相关节点的level,不如DFS写起来简洁,DFS就相当于遇到该level,对应的值就++,DFS,BFS都已列出

#include
using namespace std;
int N,M;
vector child[110];
int num[110]={0};
int levels[110]={0};
//void DFS(int index,int level)
//{
//  num[level]++;
//  if(child[index].size()==0)
//      return;
//  for(int i=0;i Q;
    Q.push(index);
    levels[index]=1;
    while(!Q.empty())
    {
        int tmp=Q.front();
        num[levels[tmp]]++;
        Q.pop();
        for(int i=0;imaxNum)
        {
            maxNum=num[n];
            maxLevel=n;
        }
    
    }
    printf("%d %d\n",maxNum,maxLevel);
    return 0;
}

你可能感兴趣的:(A1094-The Largest Generation)