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) ...
随机推荐
- Leetcode#137 Single Number II
原题地址 遍历所有数字,统计每一位出现的次数,模3即为只出现一次的数字在那一位的情况. 代码: int singleNumber(int A[], int n) { ] = {}; ; i < ...
- 系统使用 aspose.cell , 使得ashx第一次访问会变很慢
网站放在IIS后, 在网站第一次访问后. 回收应用程序池 第一次访问aspx页面还是比较快. 但第一次访问ashx会很慢. 后发现原因: aspose.cell的5.3...版本. 的原 ...
- 关于gzip压缩
关于gzip压缩 http://httpd.apache.org/docs/2.0/mod/mod_deflate.html http://www.phpchina.com/resource/manu ...
- ASP.NET页面优化性能提升方法记录
今天与大家分享:一种优化页面执行速度的方法.采用这个方法,可以使用页面的执行速度获得[8倍]的提升效果. 为了让您对优化的效果有个直观的了解,我准备了下面的测试结果截图: 测试环境:1. Window ...
- Chapter 3
1.序列类型可以使用成员操作符in,大小计算函数(len()),分片([]),都可以迭代.Python内置的序列类型:str,list,tuple,bytearray,bytes.标准库中的序列类型: ...
- ASP.NET 将Excel导入数据库
将Excel导入数据库大致流程: Excel数据->DataSet->数据库 需要做的准备:1.FileUpload控件一个,按钮一个,如果需要即时显示那么GridView或DataGr ...
- 【面试题041】和为s的两个数字VS和为s的连续正数序列
[面试题041]和为s的两个数字VS和为s的连续正数序列 题目一: 输入一个递增排序的数组和一个数字s,在数组中查找两个数,使得它们的和正好是s.如果有多对数字的和等于s,输出任意一对即可. ...
- HDU 2048 神、上帝以及老天爷(递归,错排,dp,概率)
中文题,错排,求概率,不解释,核心思路同 HDU 1465 错排简单思路可看:http://www.cnblogs.com/laiba2004/p/3235934.html //错排,但是我之前叫了几 ...
- LA 3211
As you must have experienced, instead of landing immediately, an aircraft sometimes waits in a holdi ...
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...