UVA 1292 十二 Strategic game
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
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
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std; vector <int> a[];
int dp[][],vis[]; void dfs(int o)
{
vis[o]=;dp[o][]=;dp[o][]=;
for(int i=;i<a[o].size();i++)
{
int v=a[o][i];
if(vis[v]==) continue;
dfs(v);
dp[o][]=dp[o][]+min(dp[v][],dp[v][]);
dp[o][]=dp[o][]+dp[v][];
}
return;
} int main()
{
int n,m,x,y;
int i,j,k;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<=n;i++)
a[i].clear();
memset(dp,,sizeof(dp));
memset(vis,,sizeof(vis));
while(n--)
{
scanf("%d:(%d)",&x,&m);
for(i=;i<=m;i++)
{
scanf("%d",&y);
a[x].push_back(y);
a[y].push_back(x);
}
} dfs();
printf("%d\n",min(dp[][],dp[][]));
}
return ;
}
UVA 1292 十二 Strategic game的更多相关文章
- 树形DP UVA 1292 Strategic game
题目传送门 /* 题解:选择一个点,它相邻的点都当做被选择,问最少选择多少点将所有点都被选择 树形DP:dp[i][0/1]表示当前点选或不选,如果选,相邻的点可选可不选,取最小值 */ /***** ...
- uva 1292 树形dp
UVA 1292 - Strategic game 守卫城市,城市由n个点和n-1条边组成的树,要求在点上安排士兵,守卫与点相连的边.问最少要安排多少士兵. 典型的树形dp.每一个点有两个状态: dp ...
- 前端开发中SEO的十二条总结
一. 合理使用title, description, keywords二. 合理使用h1 - h6, h1标签的权重很高, 注意使用频率三. 列表代码使用ul, 重要文字使用strong标签四. 图片 ...
- CRL快速开发框架系列教程十二(MongoDB支持)
本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...
- 我的MYSQL学习心得(十二) 触发器
我的MYSQL学习心得(十二) 触发器 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数 ...
- Web 前端开发精华文章推荐(jQuery、HTML5、CSS3)【系列十二】
2012年12月12日,[<Web 前端开发人员和设计师必读文章>系列十二]和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HT ...
- 第十二章Fundamental Data Types 基本数据类型
目录: 12.1 数值概论 12.2整数 12.3浮点数 12.4 字符和字符串 12.5布尔变量 12.6枚举类型 12.7具名常量 12.8数组 12.9创建你自己的类型 12.1 数值概论 ...
- [分享] IT天空的二十二条军规
Una 发表于 2014-9-19 20:25:06 https://www.itsk.com/thread-335975-1-1.html IT天空的二十二条军规 第一条.你不是什么都会,也不是什么 ...
- Bootstrap <基础三十二>模态框(Modal)插件
模态框(Modal)是覆盖在父窗体上的子窗体.通常,目的是显示来自一个单独的源的内容,可以在不离开父窗体的情况下有一些互动.子窗体可提供信息.交互等. 如果您想要单独引用该插件的功能,那么您需要引用 ...
随机推荐
- json和字符串/数组/集合的互相转换の神操作总结
一:前端字符串转JSON的4种方式 1,eval方式解析,恐怕这是最早的解析方式了. function strToJson(str){ var json = eval('(' + str + ')') ...
- 夺命雷公狗---微信开发17----自定义菜单的事件推送,响应菜单的CLICK
废话不多说,index.php 代码如下所示: <?php /** * wechat php test */ //define your token require_once "com ...
- 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版
<zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...
- PHPCMS V9 环境搭建
PHPCMS V9的学习总结分为以下几点: [1]PHPCMS 简介 PHP原始为Personal Home Page的缩写,(外文名:PHP: Hypertext Preprocessor,中文名: ...
- jenkins相关
1. jenkins maven tomcat做持续集成的时候几个关键配置:http://my.oschina.net/congqian/blog/112782?fromerr=PmIDbLs5 2. ...
- javaWeb 使用jsp开发 foreach 标签
1.jsp代码 测试数据 <% List<String> list = new ArrayList<String>(); list.add("aaa" ...
- linux内核栈用户栈切换【转】
转自:http://www.kerneltravel.net/kernel-book/%E7%AC%AC%E5%9B%9B%E7%AB%A0%20%E8%BF%9B%E7%A8%8B%E6%8F%8F ...
- 收缩 虚拟硬盘 shrink vhd
在使用WIN2012 的Hyper-v的虚拟磁盘时, 有时需要将磁盘中未使用的控件收缩掉, 这时就需要使用Hyper-v磁盘工具的收缩功能. 如果使用Hyper-v磁盘工具, 不能对vhd虚拟磁盘进行 ...
- centos7重启rsyslog服务|centos7重启syslog服务
centos7重启rsyslog服务: systemctl restart rsyslog 使用:(killall无效) killall -HUP rsyslog
- 完整学习git三 查看暂存区目录树 git diff
1显示暂存区中的目录树 git ls-files git ls-tree git diff 魔法 1工作区与暂存区比较 git diff 2工作区与HEAD比较 git diff HEAD 3暂存区与 ...