hdoj-1068(二分图的最小点覆盖)
1 问题转化: 求二分图最小点覆盖(覆盖所有的边)
2 问题的解决: 二分图最小点覆盖==其最大匹配数
3 证明: 链接
=#include <bits/stdc++.h>
using namespace std;
const int N = ;
vector < vector <int> > g(N);
int match [N];
bool visit[N];
int n;
bool dfs (int x) {
for (int i=;i<g[x].size();i++) {
int t=g[x][i];
if (!visit[t]) {
visit[t]=;
if (match[t]<||dfs(match[t])) {
match[t]=x;
return ;
}
}
}
return ;
}
int main ()
{
while (~scanf ("%d", &n)) {
for (int i=;i<n;i++) g[i].clear();
memset (match,-,sizeof(match));
for (int i = ; i <= n; i++) {
int id, num;
scanf ("%d: (%d)", &id, &num);
for (int j = ; j < num;j++) {
int u; scanf ("%d", &u);
g[id].push_back(u);
}
}
int ans = ;
for (int i = ; i < n; i++) {
memset (visit, , sizeof(visit));
if (dfs(i)) ans++;
}
printf("%d\n", n - ans / );// 为什么/2 因为二分图两边都遍历了
}
return ;
}
hdoj-1068(二分图的最小点覆盖)的更多相关文章
- 二分图匹配 + 最小点覆盖 - Vertex Cover
Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点 ...
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题
POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...
- POJ 1274 The Perfect Stall(二分图 && 匈牙利 && 最小点覆盖)
嗯... 题目链接:http://poj.org/problem?id=1274 一道很经典的匈牙利算法的题目: 将每只奶牛看成二分图中左边的点,将牛圈看成二分图中右边的点,如果奶牛看上某个牛圈,就将 ...
- HDU 2063 过山车(二分图 && 匈牙利 && 最小点覆盖)
嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 这是一道很经典的匈牙利问题: 把男同学看成左边点,女同学看成右边点,如果两个同学愿意同 ...
- HDU 1150 Machine Schedule (二分图最小点覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...
- 【Learning】最小点覆盖(二分图匹配) 与Konig定理证明
(附一道例题) Time Limit: 1000 ms Memory Limit: 128 MB Description 最小点覆盖是指在二分图中,用最小的点集覆盖所有的边.当然,一个二分图的最小 ...
- POJ3041 Asteroids(二分图最小点覆盖)
Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...
- 四川第七届 D Vertex Cover(二分图最小点覆盖,二分匹配模板)
Vertex Cover frog has a graph with nn vertices v(1),v(2),…,v(n)v(1),v(2),…,v(n) and mm edges (v(a1), ...
随机推荐
- redis sentinel哨兵模式集群搭建教程
1.环境说明 我们将使用192.168.220.128.192.168.220.129两台机器搭建sentinel交叉主从为例 当前我们已在192.168.220.128上按redis安装教程安装了r ...
- xshellDoc_1base
1◆ 到根目录 cd / 2◆ 创建文件夹 mkdir test 3◆ 到目录 cd /root/test/~~ 4◆修改文件名 mv test testbak 5◆ 查看 ls ...
- install the Mondo Rescue utility in Ubuntu 12.04 or 12.10.
1. Open a terminal window. 2. Type in the following commands, then hit Enter after each. wget ft ...
- 逆袭之旅DAY20.xia.师父指导.数据类型
2018-07-16 09:35:57 基础是王道 从码农--软件工程师--软件架构师 String 首字母大写,特殊引用类型,常量类 二.数组 存钱罐(只能放钱) 数据兼容 数组的长度(定义后长度 ...
- laravel 连表查询数据库
$this->model ->select($field) ->leftJoin('b', 'b.cid', '=', 'a.id') ->orderBy("a.ad ...
- Uva LA 3177 - Beijing Guards 贪心,特例分析,判断器+二分,记录区间内状态数目来染色 难度: 3
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- new_images
/home/westward/Pictures/Screenshot from 2017-03-19 20:23:55.png
- Mac 无需网线创建ipv6环境
首先需要准备Mac一台 iPhone 2部(其中一部用于测试你的项目,请装上你的应用) 连接线一根 第一步:通过数据线连接iphone和mac 第二步:打开iphone的个人热点并选择仅USB 如果没 ...
- 下载python中package的简便方法
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx
- vs2013 跳过IE10
安装 VS2013要安装IE10,却安装不了..以下为跳过IE10,直接安装VS2013方法 复制以下代码,保存为bat文件 @ECHO OFF :IE10HACK REG ADD "HKL ...