|
||||||||||
The magic apple treeTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1704 Accepted Submission(s): 391 Problem Description Sailormoon girls all like eating many kinds of fruit, such as banana, grape, apple and so on. One day, when they was walking on a orchard, they found a magic apple tree.The magic apple tree have many nodes,but there is only one root. Each notes has its label. It is labeled from 1.On the first day,only each leaf nodes(has no children nodes) have apples. Any other nodes have no apples. The number of apples that each leaf nodes have is just the label of this node.When all the immediate children of a node each has apples,this node will grow some apple on the next day. If a node has K immediate children node,the number of apple that this node grow on next day is just the number of apples that the (K + 1) / 2th smaller node has.The Xth smaller node means there are X ¨C 1 nodes¡¯ number of apples is less than this node¡¯s number of apple. Now you task is to calculate the number of apples that the root has at last. Input There are multiple test cases. Each case contains a positive integer N, it means this tree has N nodes, labeled 1, 2, ... N(0 < N <= 20000). The following N lines describe the children of all nodes in order of their labels. The (X + 1)th line in each test case starts with a number p (0 <= p <N), it means the Xth node has p immediate children nodes.then followed by p positive integer, means the label of immediate child node Output Print the number of apples that the root grow at last. Sample Input
Sample Output
Author B.A.C Source | ||||||||||
|