*HDU 1054 二分图
Strategic Game
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7651 Accepted Submission(s): 3645
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:
2
// 模板 最小点覆盖=最大匹配(有向图);最小点覆盖=最大匹配/2(无向图); 本题数据较大要用邻接表优化。(假如选了一个点就相当于覆盖了以它为端点的所有边,你需要选择最少的点来覆盖所有的边。)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int vis[],link[];
int Mu,Mv,n; //Mu,Mv分别是左集合点数和右集合点数
vector<int>mp[];
int dfs(int x) //找增广路
{
for(int i=;i<mp[x].size();i++)
{
int y=mp[x][i];
if(!vis[y])
{
vis[y]=;
if(link[y]==-||dfs(link[y]))
{
link[y]=x;
return ;
}
}
}
return ;
}
int Maxcon()
{
int ans=;
memset(link,-,sizeof(link));
for(int i=;i<Mu;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i)) ans++;
}
return ans;
}
int main()
{
int a,b,c;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++)
mp[i].clear();
memset(mp,,sizeof(mp));
for(int i=;i<n;i++)
{
scanf("%d:(%d)",&a,&c);
while(c--)
{
scanf("%d",&b);
mp[a].push_back(b);
mp[b].push_back(a);
}
}
Mv=Mu=n;
printf("%d\n",Maxcon()/);
}
return ;
}
*HDU 1054 二分图的更多相关文章
- HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)
d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...
- HDU 1054
http://acm.hdu.edu.cn/showproblem.php?pid=1054 二分图最少顶点覆盖,模板题,双向边最后结果/2 #include <iostream> #in ...
- hdu 5727 二分图+环排列
Necklace Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU - 1054 Strategic Game (二分图匹配模板题)
二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdi ...
- HDU 1054 Strategic Game(无向二分图的最大匹配)
( ̄▽ ̄)" //凡无向图,求匹配时都要除以2 #include<iostream> #include<cstdio> #include<algorithm&g ...
- HDU 1054 Strategic Game (最小点覆盖)【二分图匹配】
<题目链接> 题目大意:鲍勃喜欢玩电脑游戏,特别是战略游戏,但有时他无法找到解决方案,速度不够快,那么他很伤心.现在,他有以下的问题.他必须捍卫一个中世纪的城市,形成了树的道路.他把战士的 ...
- HDU 1054 Strategic Game(最小路径覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题目大意:给你一棵树,选取树上最少的节点使得可以覆盖整棵树. 解题思路: 首先树肯定是二分图,因 ...
- hdu 2255 二分图最大权匹配 *
题意:说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子.这可是一件大事,关系到人民的住房问题啊.村里共有n间房间,刚好有n家老百姓,考虑到每家都要有房住(如果有老百姓没房 ...
- hdu 2444(二分图) The Accomodation of Students
http://acm.hdu.edu.cn/showproblem.php?pid=2444 大意是给定n个学生,他们之间可能互相认识,首先判断能不能将这些学生分为两组,使组内学生不认识: 现想将学生 ...
随机推荐
- Scrum Meeting ——总结
冲刺总结 0*.燃尽图 迟来的燃尽图,别看它是最后一天掉了一堆,感觉很假,像是人为的把issues都关闭掉.其实不然,很多功能是大家平时做好,但是没整合在一起,所以没燃掉,在最后几天的整合中,通过测试 ...
- mongDB-- 3. 查询操作
1. 准备工作 (1)启动mongo 进入mongo安装目录的bin/ 目录 , ./mongod (2)启动mongo客户端 ./mongo (3) 查看所有库 show dbs; (4) 切换到l ...
- jQuery源码笔记(二):定义了一些变量和函数 jQuery = function(){}
笔记(二)也分为三部分: 一. 介绍: 注释说明:v2.0.3版本.Sizzle选择器.MIT软件许可注释中的#的信息索引.查询地址(英文版)匿名函数自执行:window参数及undefined参数意 ...
- HTTP响应消息中的状态代码
- 读书笔记<白帽子讲web安全>
2016年3月24日 09:34:32 星期四 ddos攻击: 一种: 随机生成ip, 去建立链接, 由于http/tcp握手协议原理, 发送应答报文时因为ip无效会导致等待重发, 这种行为可以通过电 ...
- SQLServer2008设置 开启远程连接
SQLServer2008设置 开启远程连接 前一段时间,学生分组做项目,使用SVN工具,要求功能使用存储过程,在数据库这块出现这么一个问题: A学生在他的数据库上添加了存储过程,需要其他的B,C,D ...
- HTML CSS SPRITE 工具
推荐一个CSS SPRITE工具 网盘分享:http://pan.baidu.com/s/1sjx7cZV
- iOS中滤镜处理及相关内存泄漏问题的解决
最近工作之余在做一个美图秀秀的仿品 做到滤镜这块的时候 自己就参考了网上几位博主(名字忘了记,非常抱歉)的博客,但是发现跟着他们的demo做的滤镜处理,都会有很严重的内存泄漏,于是就自己按照大体的思 ...
- Huffman的应用_Huffman编码
//最优二叉树 #include <iostream> #include <iomanip> using namespace std; //定义结点类型 //[weight | ...
- python:列表与元组
1.python包含六种内建的序列,列表和元组是其中的两种,列表可以修改,元组则不能 2.通用序列操作 2.1 索引:和C#的区别是索引可以为负数,最后一个元素索引为-1,索引超出范围会报错 例:&g ...