字典数据结构实现标识符的输出,使用C语言的程序的编写的步骤方式怎么才能解答呢?

Problem Description
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:

Sample Input
4
0:(1) 1
1:(2) 2 3
2:(0)
3:(0)
5
3:(3) 1 4 2
1:(1) 0
2:(0)
0:(0)
4:(0)

Sample Output
1
2

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

2
tensorflow如何将数组中的元素按照字典中的向量进行赋值?
2
Python如何判断一个字符串是否一个字典中存在的英文单词?
0
初学字符串的实际工程问题4,5,6
1
C程序输出题目所要求的序列,序列中每个元素一行。如果存在两个符合要求的序列
2
python如何把list中的字典结构 循环存储到MYSQL中?
4
python中如何在获取好了的列表中的字典 如何输出字典的值,键已经锁定了(不用输出)。
3
Python中字典数据怎么求取其中的最值
1
python字典配合占位符出错
2
python处理txt文件,怎么把文本形式的数据处理成字典
0
KSVD算法中怎么初始化字典?
3
python中的字典赋值问题???
0
哈密顿回路的一个算法问题计算经过的节点,采用C语言程序的设计的办法怎么做
1
拍卖竞价的一个应用题的算法的实现,怎么采用C语言的程序的设计的形式来实现的呢
3
c语言 给国家的名称按字典顺序排序
0
Excel可以对一组纪录按任意指定列排序。用C语言编程编写程序实现类似功能
2
急求!!!请问我错在哪里?以及怎么改?谢谢!!!c语言 给国家的名称按字典顺序排序
3
急求!!!请问我的哪里错了?怎么改?谢谢!!!c语言 给国家的名称按字典顺序排序
0
谁有汉字字典的数据库SQl,或者英文字典的数据库SQl,能分享下吗!
2
编写一个程序c++,对输入的n(n<100)本书进行排序并输出?
1
DICOM 某个TAG的VR可以和数据字典中不同吗?