Strategic Game

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 6586    Accepted Submission(s): 3066

Problem Description
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.



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:
 
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
 
Source
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1068 1150 1151 1281 1142 
 

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#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的更多相关文章

  1. HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)

    d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...

  2. HDU 1054 Strategic Game(最小路径覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题目大意:给你一棵树,选取树上最少的节点使得可以覆盖整棵树. 解题思路: 首先树肯定是二分图,因 ...

  3. HDU 1054 Strategic Game(树形DP)

    Problem Description Bob enjoys playing computer games, especially strategic games, but sometimes he ...

  4. HDU 1054 Strategic Game(树形DP)

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. hdu 1054 Strategic Game 经典树形DP

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. hdu 1054 Strategic Game (二分匹配)

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. hdu 1054 Strategic Game(tree dp)

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. HDU——1054 Strategic Game

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu 1054 Strategic Game (简单树形DP)

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. GS连接事件

    GS网络连接事件 //网络事件 //这个事件是在libevent里面的收到的事件就是在那个listen里面,就是客户端打开,服务器收到通知 link_stat stat = (link_stat)rP ...

  2. Game shader or System shader is busy ::VS CSG

    this error means The GPU is freezen Phyre::PSemaphoreOrbis::wait()//callstack something illegal in c ...

  3. Notes on the Dirichlet Distribution and Dirichlet Process

    Notes on the Dirichlet Distribution and Dirichlet Process In [3]: %matplotlib inline   Note: I wrote ...

  4. Linux常用命令大全(转载)

    系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...

  5. CKEditor (Toolbar Definition)工具栏自定义配置

    JS是大小写敏感的, 在设置配置文件的时候需要注意 以CKEditor 4为基础我们可以通过两种方式配置CKEditor的工具栏,一种是是通过config.js配置文件设置, 另一种是IN-PAGE方 ...

  6. Sqli-labs less 30

    Less-30 Less-30与less-29原理是一致的,我们可以看到less-30的sql语句为: 所以payload为: http://127.0.0.1:8080/sqli-labs/Less ...

  7. 2014ACM-ICPC 西安赛区总结

    万万没想到,打铁了.以前一直觉得拿铁咖啡的梗是很好笑的,然后有一天这杯咖啡自己喝下去了,就会发现心里真的被梗住了. 复旦的题其实我是有预料到的,前年的复旦题三题从金区到铜区都有,但是从去年的南京赛区开 ...

  8. Codeforces449A Jzzhu and Chocolate && 449B Jzzhu and Cities

    CF挂0了,简直碉堡了.两道题都是正确的思路但是写残了.写个解题报告记录一下心路历程. A题问的是 一个n*m的方块的矩形上切k刀,最小的那一块最大可以是多少.不难发现如果纵向切k1刀,横向切k2刀, ...

  9. POJ 1969

    #include <iostream> #include <cmath> using namespace std; int main() { //freopen("a ...

  10. Lock wait timeout exceeded; try restarting transaction

    What gives this away is the word transaction. It is evident by the statement that the query was atte ...