Concrete train of thought is that each node storing children count, id, and the layer number, enter a level number to the parents to the child according to parents children count,
Finally statistics all the nodes, number of children of 0 layer of the leaf node + 1.
# include & lt; Iostream>
# define MAX 100
using namespace std;
Struct tree {
Int ID;
Int child_num;
Int f;
};
Int main ()
{
Tree test (MAX);
Int N, M;
Int n=1;//the number of assignment
Int num={0} [MAX];//each layer of the leaf node number
Int floa=1;//layer
Cin & gt;> N;
Cin & gt;> M;
If (N==1)
{
Cout<1;
return 0;
}
The test - & gt; ID=1;
The test - & gt; Child_num=0;
The test - & gt; F=1;
For (int I=1; i{
The test [I]. ID=0;
The test [I] child_num=0;
Test [I] f=0;
}
For (int I=0; i{
Int ID, k, ID (MAX);
Cin & gt;> ID;
Cin & gt;> k;
for (int j=0; J & lt; k; J++)
Cin & gt;> Id [j];
int j=0;
for(j=0; J{
If (test [j]. ID==ID)
break;
}
j++;
The test [j - 1] child_num=k;
If (test [j - 1] f + 1 & gt; Floa)
Floa=test [j - 1] f + 1;
For (int a=0; A. & lt; k; +)
{
If (a + n>=N)
return 1;
The test [a + n]. ID=ID [a];
The test [a + n]. F=test [j - 1] f + 1;
}
N +=k;
}
For (int I=0; i{
If (test [I] child_num==0)
Num [test [I] f - 1] + +;
}
For (int I=0; i{
coutIf (I.=floa - 1)
cout <"';
}
}