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. MySQL忘记密码解决

    1.设置管理员root密码为123 开启MySQL服务后 PS C:\WINDOWS\system32> mysqladmin -uroot -p password "123" ...

  2. 使用 jsvc 启动tomcat(使用普通用户运行)

    使用 jsvc 启动tomcat(使用普通用户运行) jsvc简介 在生产中,tomcat应该以daemon的模式运行,而且如果需要以普通用户的身份启动tomcat,那么就不能使用1024以下的端口, ...

  3. 1263: 你会做蛋糕吗?(Java)

    WUSTOJ 1263: 你会做蛋糕吗? 参考博客 Mitsuha_的博客 Description BobLee是个大吃货,喜欢吃好吃的,也喜欢做好吃的.比如做正方形的蛋糕.比如下图这个5*5的蛋糕. ...

  4. 5-9 c语言之【文件】

    最近学习了在c语言中对文件的处理(此为win10操作系统),由根据<c标准库>一书针对文件处理相关函数进行了一些总结 在这里只总结了<stdio.h>头文件内的函数,头文件&l ...

  5. uncompyle6安装使用方法

    uncompyle6是一个原生python的跨版本反编译器和fragment反编译器,是decompyle.uncompyle.uncompyle2等的接替者. uncompyle6可将python字 ...

  6. Entity framework 意外删除了表,如何在不影响其它表的情况下恢复回来

    关于EntityFramework数据迁移原理 查询数据库的表"__MigrationHistory",遍历代码库的Migrations文件夹下的所有文件,如果文件不在__Migr ...

  7. 英特尔vPro博锐技术激活

    英特尔vPro博锐技术激活 参考: Intel官方Management Engine BIOS Extension (Intel®MEBX)手册:http://www.intel.com/conten ...

  8. freemarker循环、下标及判断

    一.freemarker中list循环使用非常频繁,下面介绍lfreemarker中list简单的用法 1.在freemarker中遍历list数组使用list指令:<#list sequenc ...

  9. RGB转YUV 各种库的性能比较

    分辨率   1920*1080 平台  : X64  Windows  VS2015 测试  BGR24-->YUV420 trans_scale: 4.14 ms (自己写得)libyuv  ...

  10. 监控神器-普罗米修斯Prometheus的安装

    搬砖党的福音:普罗米修斯-监控神器 功能: 在业务层用作埋点系统 Prometheus支持多种语言(Go,java,python,ruby官方提供客户端,其他语言有第三方开源客户端).我们可以通过客户 ...