//2??á??£?ê????′1y±eè?μ??áìa±¨??oó??μ?£??§?°??
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct Node
{ int label;
?? int cnt;
?? int leaf[200];
};
Node tree[200];
int solve(int i)
{?? int??stone[200],result,temp;
????if(tree[i].cnt==0)
?????? return 1;
???? for(int j=0;j<tree[i].cnt;j++)
???????? stone[j]=solve(tree[i].leaf[j]);
???? sort(stone,stone+tree[i].cnt);
???? result=stone[tree[i].cnt-1];
???? temp=result-1;
???? for(int k=tree[i].cnt-2;k>=0;k--)
????????{ if(temp-stone[k]>=0)
???????????? temp--;
?????????? else
???????????? {result=result+stone[k]-temp;
??????????????temp=stone[k]-1;
??????????????}
???????? }
?????? return result;
}
int main()
{ int n,m;
??freopen("in.txt","r",stdin);
??freopen("out.txt","w",stdout);
??scanf("%d",&n);
??while(n--)
?????? { scanf("%d",&m);
???????? for(int i=1;i<=m;i++)
???????????? {??scanf("%d%d",&tree[i].label,&tree[i].cnt);
????????????????for(int j=0;j<tree[i].cnt;j++)
?????????????????? scanf("%d",&tree[i].leaf[j]);
??????????????}
???????? printf("%d\n",solve(1));
?????? }
?? return 0;
}
|