Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a tree. He has to put the minimum number of soldiers on the nodes so that they can observe all the edges. Can you help him?
Your program should find the minimum number of soldiers that Bob has to put for a given tree.
The input file contains several data sets in text format. Each data set represents a tree with the following description:
the number of nodes
the description of each node in the following format
node_identifier:(number_of_roads) node_identifier1 node_identifier2 ... node_identifier
or
node_identifier:(0)
The node identifiers are integer numbers between 0 and n-1, for n nodes (0 < n <= 1500). Every edge appears only once in the input data.
For example for the tree:
the solution is one soldier ( at the node 1).
The output should be printed on the standard output. For each given input data set, print one integer number in a single line that gives the result (the minimum number of soldiers). An example is given in the following table:
翻译:
Bob喜欢玩电脑游戏,特别是策略游戏,但是有时他不能足够快地找到解决方法,所以他很难过。现在他有如下难题。他必须保卫一座中世纪城市,那里的道路形成一棵树。他需要在节点上放置最少数量的士兵,以便他们能观察所有边界。你能帮助他吗?你的程序应该找到Bob给定树应该放置的最少士兵数。输入文件包含几个文本格式的数据集。每个数据集代表一棵树,有以下描述:节点数,每个节点的描述格式如下:节点标识符:(树的数量)节点标识符1 节点标识符2....节点标识符或者节点标识符:(0)。
对于n个节点(0<=n<=1500),节点标识符是介于0到n-1之间的整数。每个边界在输入数据中只会出现一次。例如这棵树:
解决方法是一个士兵(在节点1)。输出应该打印在标准输出上。对每个给定的输入数据集,在一行中打印一个整数,给出结果(最少的士兵数)。一个样例如下表: