/*
【题意】 给定一棵树,标记一节点,则与该节点所连的边都被标记,问最少需要标记多少个节点使得所有边都被标记;
或者说给定一个树型城堡,在交叉路口放一个士兵,则与该路口相连的路都被守住,
问最少需要派遣多少个士兵来守住这个城堡 dp[father].yes= ( min(dp[child].yes,dp[child].no) 之和)
dp[father].yes=( min(dp[child].yes,dp[child].no) 之和) */
#include<stdio.h>
#include<string.h> struct node
{
int father,brother,child;
int yes,no; void init()
{
father=brother=child=0;
yes=1;
no=0;
}
}t[1505]; bool use[1505];
int min(int x,int y)
{
if(x<y) return x;
return y;
} void dfs(int root)
{
int child=t[root].child;
while(child)
{
dfs(child);
t[root].yes+=min(t[child].yes,t[child].no);
t[root].no+=t[child].yes;
child=t[child].brother;
}
}
/*
void dfs(int root)
{
int child=t[root].child;
while(child)
{
dfs(child);
printf("root%d %d",root,child);
child=t[child].brother;
}
}*/ int main()
{
int n,Root,root,cnt,j;
while(scanf("%d",&n)!=EOF)
{
memset(use,0,sizeof(use)); //int Root; for(int i=1;i<=n;i++)
{
scanf("%d:(%d)",&root,&cnt),root++;
if(i==1) Root=root; if(!use[root])
{
t[root].init();
use[root]=1;
} while(cnt--)
{
scanf("%d",&j),j++;
if(!use[j])
{
t[j].init();
use[j]=1;
}
t[j].brother=t[root].child;
t[j].father=root;
t[root].child=j;
}
} dfs(Root); printf("%d\n",min(t[Root].no,t[Root].yes)); } return 0;
}

最新文章

  1. 非域客户端的office使用RMS加密服务出现&lsquo;介绍&ldquo;信息权限管理服务&rdquo;&rsquo;服务的提示
  2. CSS3 Gradient 渐变
  3. hibernate-取消关联外键引用数据丢失抛异常的设置@NotFound
  4. php部分---面向对象,设计模式(单例模式、工厂模式)、oop六大原则;
  5. python主要用来做什么
  6. C语言,一个彩票摇奖程序摇出22选5的中奖号码
  7. css中的img和input标签
  8. pcDuino安装vnc进行远程控制
  9. [置顶] Linux下的截图小工具
  10. Scala Web 框架——Lift(一)准备工作
  11. winform / Dev全局皮肤组件
  12. oracle运行速度与效率高的秘密
  13. Vue之彻底理解自定义组件的v-model
  14. 《python语言程序设计》_第一章编程题
  15. .NET正则平衡组
  16. CSS笔记——属性选择器
  17. forEach的坑
  18. C#学习笔记(25)——用刻盘器批量从U盘删除添加文件
  19. Let the Balloon Rise map一个数组
  20. Good Bye 2018 Solution

热门文章

  1. centos web+mysql服务器的安全
  2. 登陆获取shell时的配置文件加载过程
  3. SpringCloud之客户端连接Eureka集群
  4. MySql-rules
  5. 彻底搞懂word-break、word-wrap、white-space
  6. JS中不同类型的值比较问题
  7. php发邮件:swiftmailer, php邮件库——swiftmailer
  8. Jquery 取值,赋值学习总结
  9. POJ 2421 Constructing Roads(Kruskal算法)
  10. 再次理解WCF以及其通信(附加一個編程小經驗)