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 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);the number_of_roads in each line of input will no more than 10. 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). An example is given in the following:

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。
题意:在无向图中,在某一点放置士兵,该士兵可以守护与该点相邻的其他点,求出要保护所有点的最少士兵数。
思路:求最小点覆盖。。最小点覆盖数 = 最大匹配数
AC代码:
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <vector> using namespace std;
#define maxn 2500
int vis[maxn];
int match[maxn];
vector<int> v[maxn];
int n;
int dfs(int u){ // 匈牙利模板
for(int i=;i<v[u].size();i++){
int temp=v[u][i];
if(vis[temp]==){
vis[temp]=;
if(match[temp]==||dfs(match[temp])){
match[temp]=u;
return ;
}
}
}
return ;
}
int main(){
while(~scanf("%d",&n)){
for(int i=;i<=n;i++)
v[i].clear();
for(int i=;i<=n;i++){
int x,m,y;
scanf("%d:(%d)",&x,&m);
for(int j=;j<m;j++){
scanf("%d",&y);
v[x].push_back(y);
v[y].push_back(x);
}
}
memset(match,,sizeof(match));
int ans=;
for(int i=;i<n;i++){
memset(vis,,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%d\n",ans/);
}
return ;
}
												

Strategic game POJ - 1463 【最小点覆盖集】的更多相关文章

  1. POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)

    题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...

  2. POJ 3041 Asteroids (最小点覆盖集)

    题意 给出一个N*N的矩阵,有些格子上有障碍,要求每次消除一行或者一列的障碍,最少消除多少次可以全部清除障碍. 思路 把关键点取出来:一个障碍至少需要被它的行或者列中的一个消除. 也许是最近在做二分图 ...

  3. POJ 3041 Asteroids (二分图最小点覆盖集)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24789   Accepted: 13439 Descr ...

  4. hdu 1054(最小点覆盖集)

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

  5. 树形dp compare E - Cell Phone Network POJ - 3659 B - Strategic game POJ - 1463

    B - Strategic game POJ - 1463   题目大意:给你一棵树,让你放最少的东西来覆盖所有的边   这个题目之前写过,就是一个简单的树形dp的板题,因为这个每一个节点都需要挺好处 ...

  6. ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)

    //匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...

  7. POJ2226 Muddy Fields(二分图最小点覆盖集)

    题目给张R×C的地图,地图上*表示泥地..表示草地,问最少要几块宽1长任意木板才能盖住所有泥地,木板可以重合但不能盖住草地. 把所有行和列连续的泥地(可以放一块木板铺满的)看作点且行和列连续泥地分别作 ...

  8. POJ1325 Machine Schedule(二分图最小点覆盖集)

    最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...

  9. Jewelry Exhibition(最小点覆盖集)

    Jewelry Exhibition 时间限制: 1 Sec  内存限制: 64 MB提交: 3  解决: 3[提交][状态][讨论版] 题目描述 To guard the art jewelry e ...

  10. 二分图变种之最小路径覆盖、最小点覆盖集【poj3041】【poj2060】

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=54859604 向大(hei)佬(e)势力学(di ...

随机推荐

  1. mac 安装 navicat for mysql 破解版

    mac 安装 navicat for mysql 破解版,直接安装,亲测可用 首先打开mac控制台输入命令行:sudo spctl --master-disable 百度盘,提取码: vrtr 失效请 ...

  2. docker 实践四:仓库管理

    本篇我们来了解 docker 仓库的内容. 注:环境为 CentOS7,docker 19.03 仓库(Responsitory)是集中存放镜像的地方,又分公共仓库和私有仓库. 注:有时候容易把仓库与 ...

  3. go if 判断 完成随机分数的评级

    1 go中 所有的大括号要跟在 当前语句的后面不能换行 例如: if a>0  { func getUser(){ for { 2关于随机分数的生成 种子的设置放到循环中会是重复的数字,这是可以 ...

  4. (三)Redis之数据结构概念以及数据结构之字符串

    一.数据结构 五种数据类型: 字符串(String) 字符串列表(list) 有序字符串集合(sorted set) 哈希(hash) 字符串集合(set) 二.数据结构之字符串 二进制安全的,存入和 ...

  5. (七)发送、接收SOAP消息(以HttpClient方式)(2)

    一.为什么要用soap 原本我们使用web服务都是根据wsdl生成客户端(生成一堆java文件)然后再调用,本章节讲解如何用soap消息来替代这种方式. 二.SOAP消息格式 SOAP(简单对象访问协 ...

  6. Jar包下载 开源网站 模板下载

    在日常的java学习和开发中,总是遇到各种jar包下载,但是CSDN这种坑爹网站,各位码农们都想挣点C币,一个开源的免费的东西就这么变了味,我这里收集 了一些好用的工具,日常开发中需要用的请自取,毕竟 ...

  7. java 框架-企业级搜索 Solr

    https://blog.csdn.net/cs_hnu_scw/article/details/79388080 一:Solr简介       Solr是一个独立的企业级搜索应用服务器,它对外提供类 ...

  8. [转载]Java中继承、装饰者模式和代理模式的区别

    [转载]Java中继承.装饰者模式和代理模式的区别 这是我在学Java Web时穿插学习Java设计模式的笔记 我就不转载原文了,直接指路好了: 装饰者模式和继承的区别: https://blog.c ...

  9. 多态——virtual

    作用:解决当使用基类的指针指向派生类的对象并调用派生类中与基类同名的成员函数时会出错(只能访问到基类中的同名的成员函数)的问题,从而实现运行过程的多态 不加virtual #include<io ...

  10. C++ sizeof(struct) 的注意

    今天在测试将C++代码导出的NavMesh二进制文件用一套C#改写的代码导入时,发现导入的数据出现不一致的问题. 分别在C++和C#AddTile的函数内设置断点,观察最后得到的tile有大部分的字段 ...