Topic Information
1094. The largest Generation (25)
Time limit of MS
Memory Limit 65536 KB
Code length limit 16000 B
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same genera tion. Your task is to find the generation with the largest population.
Input Specification:
Each input file contains the one test case. Each case starts with a positive integers N (<100) which is the total number of family members in the tree (and hence Assume that all the members were numbered from () to N), and M (less than N) which is the number of the family members who had childre N. Then M. lines follow, each contains the information of a family member in the following format:
ID K id[1] id[2] ... ID[K]
Where ID is a two-digit number representing a family member, K (>0) are the number of his/her children, followed by a SE Quence of Two-digit ID ' s of his/her children. For the sake of simplicity, let us fix the root ID to be 01. All the numbers in a line is separated by a space.
Output Specification:
For each test case, print on one line the largest population number and the level of the corresponding generation. It is assumed that such a generation are unique, and the root level was defined to be 1.
Sample Input:
23 13
21 1 23
01 4 03 02 04 05
03 3 06) 07 08
06 2 12 13
13 1 21
08 2 15 16
02 2 09 10
11 2 19 20
17 1 22
05 1 11
07 1 14
09 1 17
10 1 18
Sample Output:
9 4
Thinking of solving problems
Two-fork Tree
AC Code
#include <cstdio>#include <vector>using namespace STD; vector<int>node[ the];intlevel[ the];voidDfsintRootintLV) {level[lv]++; for(inti =0; I < node[root].size (); ++i) {DFS (node[root][i], LV +1); }}intMain () {intN, K, id, TN, t;scanf("%d%d", &n, &k); for(inti =0; I < K; ++i) {scanf("%d%d", &id, &TN); for(intj =0; J < TN; ++J) {scanf("%d", &t); Node[id].push_back (t); }} DFS (1,1);intMX =1, Mxid =1; for(inti =1; I <= N; ++i) {if(Level[i] > mx) {mx = level[i]; Mxid = i; } }printf("%d%d\n", MX, MXID);return 0;}
1094. The largest Generation (25) "Binary Tree"--pat (Advanced level) practise