Strategic Game

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7651    Accepted Submission(s): 3645

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
 
题意:
找二分图最小点覆盖
代码:
 // 模板  最小点覆盖=最大匹配(有向图);最小点覆盖=最大匹配/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 二分图的更多相关文章

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

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

  2. HDU 1054

    http://acm.hdu.edu.cn/showproblem.php?pid=1054 二分图最少顶点覆盖,模板题,双向边最后结果/2 #include <iostream> #in ...

  3. hdu 5727 二分图+环排列

    Necklace Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  4. HDU - 1054 Strategic Game (二分图匹配模板题)

    二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdi ...

  5. HDU 1054 Strategic Game(无向二分图的最大匹配)

    ( ̄▽ ̄)" //凡无向图,求匹配时都要除以2 #include<iostream> #include<cstdio> #include<algorithm&g ...

  6. HDU 1054 Strategic Game (最小点覆盖)【二分图匹配】

    <题目链接> 题目大意:鲍勃喜欢玩电脑游戏,特别是战略游戏,但有时他无法找到解决方案,速度不够快,那么他很伤心.现在,他有以下的问题.他必须捍卫一个中世纪的城市,形成了树的道路.他把战士的 ...

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

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

  8. hdu 2255 二分图最大权匹配 *

    题意:说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子.这可是一件大事,关系到人民的住房问题啊.村里共有n间房间,刚好有n家老百姓,考虑到每家都要有房住(如果有老百姓没房 ...

  9. hdu 2444(二分图) The Accomodation of Students

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 大意是给定n个学生,他们之间可能互相认识,首先判断能不能将这些学生分为两组,使组内学生不认识: 现想将学生 ...

随机推荐

  1. [Machine Learning] Learning to rank算法简介

    声明:以下内容根据潘的博客和crackcell's dustbin进行整理,尊重原著,向两位作者致谢! 1 现有的排序模型 排序(Ranking)一直是信息检索的核心研究问题,有大量的成熟的方法,主要 ...

  2. Swift3.0P1 语法指南——枚举

    原档: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programm ...

  3. @好友的EditText

    类似微信聊天中的@好友功能,封装到一个EditText中,gist打不开了,直接贴代码到这里吧: /*** @好友的输入组件*/public class AtEditText extends Edit ...

  4. Python正则表达式详解

    我用双手成就你的梦想 python正则表达式 ^ 匹配开始 $ 匹配行尾 . 匹配出换行符以外的任何单个字符,使用-m选项允许其匹配换行符也是如此 [...] 匹配括号内任何当个字符(也有或的意思) ...

  5. python之路五

    内建模块 time和datetime 在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现 ...

  6. servlet 之request

    request对象中其他功能     一.转发和包含         转发==>用于一个servlet和一个jsp合作处理             servlet用于处理逻辑.jsp用于显示   ...

  7. OSSFS将OSS bucket 挂载到本地文件系统及注意事项

    OSSFS将OSS bucket 挂载到本地文件系统及注意事项 下载ossfs安装包 wget http://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/as ...

  8. sqlserver中判断表或临时表是否存在

    转自:http://www.cnblogs.com/yugen/archive/2010/07/25/1784749.html 1.判断数据表是否存在 方法一: use yourdb;go if ob ...

  9. asp.net中membership使用oracle数据库(一)

    第一步 数据库的准备 使用 oracle 11g的数据库 需要安装好,安装过程中先决条件检查失败的处理:确认server服务已运行 cmd->net share c$=c: 就可以通过 orac ...

  10. nginx和rewrite的配置

    测试ok 具体参见 http://www.ccvita.com/348.html