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.

For example for the tree:

the solution is one soldier (at the node 1).

Input

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_identifiernumber_of_roads
    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.

Output

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).

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 DP,每个点放士兵或者不放士兵两种状态,dp[i][0] += dp[v][1] dp[i][1] += min(dp[v][1],dp[v][0]);
0代表不放,1代表放。

LA 2038的更多相关文章

  1. LA 2038 最少点覆盖

    题目链接:https://vjudge.net/problem/UVALive-2038 题意:我看了原题,lrj的书上题意写错了,应该是最少点覆盖,当然可以用最大匹配去做,由于是树形的: 可以树形D ...

  2. LA 2038 Strategic game(最小点覆盖,树形dp,二分匹配)

    题意即求一个最小顶点覆盖. 对于没有孤立点的图G=(V,E),最大独立集+最小顶点覆盖= V.(往最大独立集加点) 问题可以变成求树上的最大独立集合. 每个结点的选择和其父节点选不选有关, dp(u, ...

  3. php 2038年问题

    在mysql中存放日期时可以存放整数 (int),  而int可以存放的数据最大为4294967295(无符号), 而php最大为2147483647, 要显示一个大于2038年日期,该如何处理 ? ...

  4. HYSBZ 2038 莫队算法

    小Z的袜子(hose) Time Limit:20000MS     Memory Limit:265216KB     64bit IO Format:%lld & %llu Submit  ...

  5. leggere la nostra recensione del primo e del secondo

    La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...

  6. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  7. BZOJ 2038: [2009国家集训队]小Z的袜子(hose) [莫队算法]【学习笔记】

    2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 7687  Solved: 3516[Subm ...

  8. BZOJ 2038: [2009国家集训队]小Z的袜子(hose)

    2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 7676  Solved: 3509[Subm ...

  9. [BZOJ 2038]小Z的袜子

    传送门:BZOJ 2038 题意很明确,是在给定的区间内任意选取两个数,求选到两个相同的数的概率. 所以我们得首先统计在给定的区间内,相同的数对有多少对,那么这里就使用到了莫队算法.如果对莫队算法还不 ...

随机推荐

  1. 【原创】可以换行的RadioGroup

    0.效果截图: 以上两个RadioGroup均使用FNRadioGroup实现. 1.控件代码: public class FNRadioGroup extends ViewGroup { /** 没 ...

  2. EMVTag系列2《磁条等效数据》

    Ø 57  磁条2等效数据 L: var. up to 19 -M(必备):此数据必须存在并提供给终端,终端在读应用数据过程中,如果没有读到必备数据,终端中止交易 按GB/T 17552,磁条2的数据 ...

  3. Redis 配置文件 redis.conf 项目详解

    Redis.conf 配置文件详解 # [Redis](http://yijiebuyi.com/category/redis.html) 配置文件 # 当配置中需要配置内存大小时,可以使用 1k, ...

  4. 说说oracle中的面向对象与面向集合

    这一篇算是对近期自己学习的一个心得总结 一.oracle的面向对象 SQL是面向集合的这个大家都知道,但是不可否认现在的oracle中有很多地方都体现着面向对象的思维.(这也算是各大语言殊途同归的一个 ...

  5. hdu 1381 Crazy Search

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1381 Crazy Search Description Many people like to sol ...

  6. swift学习初步(四)-- 函数

    好了,让我们开始接着前几天写的系列博客开始今天的这篇博客.在swift里面如果你需要定义一个方法的话,你需要使用关键字:func,请看下面的这段代码: func sayHello(name:Strin ...

  7. 关于 ajax 动态返回数据 css 以及 js 失效问题

    ajax 毕竟是异步的 所以动态加载出来的数据 难免遇到 css 或者 js 失效的问题,所以要动态加载 css ji等文件了 1.公共方法 load //动态加载 js /css function ...

  8. Java实现Socket之TimeClient

    Java实现Socket之TimeClient 代码内容 从time.nist.gov服务器的37号端口得到时间信息,并对时间进行解析后显示出来 代码实现 /* TimeClient.java */ ...

  9. LinqToExcel: LINQ查询Excel电子表格

    Linq的强大人所共知,能不能将Linq扩展到读取excel呢? 答案当然是肯定的. LinqToExcel就是一个实现了使用Linq语法查询excel表格的.net开源类库. 在nuget搜索下载安 ...

  10. < java.util >-- Set接口

    Set接口中的方法和Collection中方法一致的.Set接口取出方式只有一种,迭代器. |--HashSet:底层数据结构是哈希表,线程是不同步的.无序,高效: HashSet集合保证元素唯一性: ...