原题链接:A1094 The Largest Generation
#include
#include
#include
#include
#include
using namespace std;typedef struct PTNode
{vector<int> child;
} PTNode;
PTNode PTree[100];
int N, M, K, max_width_level &#61; 1, max_width &#61; 1;void BFS(int ID)
{queue<int> Q;Q.push(ID);int level &#61; 1, width &#61; 0, last_ID &#61; 1;while(!Q.empty()){ID &#61; Q.front();Q.pop();width&#43;&#43;;for(int i&#61;0; i<(PTree[ID].child).size(); i&#43;&#43;){Q.push(PTree[ID].child[i]);}if(ID &#61;&#61; last_ID){last_ID &#61; Q.back();if(width > max_width){max_width &#61; width;max_width_level &#61; level;if(!Q.empty()) last_ID &#61; Q.back();}level&#43;&#43;;width &#61; 0;}}
}int main()
{scanf("%d %d", &N, &M);for(int i&#61;0, ID, child_id; i<M; i&#43;&#43;){scanf("%d %d", &ID, &K);for(int j&#61;0; j<K; j&#43;&#43;){scanf("%d", &child_id);(PTree[ID].child).push_back(child_id);}}BFS(1);printf("%d %d", max_width, max_width_level);return 0;
}