HDU 1054:Strategic Game
Strategic Game
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6586 Accepted Submission(s): 3066
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:
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)
1
2
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int bb[1510],aa[1510],n;
vector<int> G[1510];
bool find(int k)
{
for(int j = 0; j < (int)G[k].size(); j++)
{
int i = G[k][j];
if(!aa[i])
{
aa[i] = 1;
if(bb[i] == -1 || find(bb[i]))
{
bb[i] = k;
return true;
}
}
}
return false;
}
int main()
{
int a, b, c;
while(~scanf("%d", &n))
{
for(int i = 0; i < 1510; i++)G[i].clear();
for(int i = 0; i < n; i++)
{
scanf("%d:(%d)", &a, &c);
for(int j = 0; j < c; j++)
{
scanf("%d", &b);
G[a].push_back(b);
G[b].push_back(a);
}
}
c = 0;
memset(bb, -1, sizeof(bb));
for(int i = 0; i < n; i++)
{
memset(aa, 0, sizeof(aa));
if(find(i)) c++;
}
printf("%d\n",c>>1);
}
return 0;
}
HDU 1054:Strategic Game的更多相关文章
- HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)
d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...
- HDU 1054 Strategic Game(最小路径覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题目大意:给你一棵树,选取树上最少的节点使得可以覆盖整棵树. 解题思路: 首先树肯定是二分图,因 ...
- HDU 1054 Strategic Game(树形DP)
Problem Description Bob enjoys playing computer games, especially strategic games, but sometimes he ...
- HDU 1054 Strategic Game(树形DP)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1054 Strategic Game 经典树形DP
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1054 Strategic Game (二分匹配)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1054 Strategic Game(tree dp)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU——1054 Strategic Game
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1054 Strategic Game (简单树形DP)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- shell ulimit -n
通过ulimit -n命令可以查看linux系统里打开文件描述符的最大值,一般缺省值是1024,
- C# Redis
概念 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,和Memcached类似,它支持存储的value类型相对更多,包括string( ...
- C#_音乐播放器_用ListBox显示歌词
在用ListBox显示歌词的时候,可以显示多行,同时可以控制每一行显示的样式等等.控制显示样式是在它的DrawItem事件中来控制的.首先要先将ListBox的DrawMode属性设置为OwnerDr ...
- DB2 的create or update方法
通过merge方法实现的: MERGE INTO IFEBASE.STYLE AS MT USING (SELECT :scenario AS SCENARIO_ID, :style AS SHAPE ...
- 理解Session的几种模式
一.写在前面 我们在使用ASP.NET开发的过程中,有时会进行数据存储以实现请求前后的状态保持(HTTP是无状态保持的协议),而Session作为一种快速简单易于实现的方式被我们经常使用,当然如果出于 ...
- 原 JS监听回车事件
原 JS监听回车事件 发表于2年前(2014-06-04 10:16) 阅读(6101) | 评论(0) 11人收藏此文章, 我要收藏 赞0 1月16日厦门 OSC 源创会火热报名中,奖品多多哦 ...
- SPOJ375 Query on a tree(LCT边权)
之前做了两道点权的LCT,这次做一下边权的LCT.上网找了一下资料,发现对于边权的LCT有这么两种处理方法,一种是每条边建一个点,于是边权就转成点权了.另外一种则是每个边权对应到点权上,也就是每个点对 ...
- DB2常用函数:字符串函数
VALUE函数 语法:VALUE(EXPRESSION1,EXPRESSION2) VALUE函数是用返回一个非空的值,当其第一个参数非空,直接返回该参数的值,如果第一个参数为空,则返回第一个参数的值 ...
- 搭建jenkins环境(linux操作系统)
一.虚拟机安装 1) Virtualbox安装 2) 新建镜像(将已有镜像导入) 3) 开通本地远程访问虚拟机的权限 3.1 通过本地的mac地址设置本地连接固定的ip地址.子网掩码.默认网关 ...
- SSH乱码和Xshell异常断开解决方法
一.SSH Secure Shell Client中文乱码的解决方法 这是SSH Secure Shell Client多年未解决的短板,要求客户端和服务器端都要‘UTF-8’编码,我终于知道Wind ...