题目

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(二分图的最小点覆盖)的更多相关文章

  1. 二分图匹配 + 最小点覆盖 - Vertex Cover

    Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点 ...

  2. hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...

  3. POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题

    POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...

  4. POJ 1274 The Perfect Stall(二分图 && 匈牙利 && 最小点覆盖)

    嗯... 题目链接:http://poj.org/problem?id=1274 一道很经典的匈牙利算法的题目: 将每只奶牛看成二分图中左边的点,将牛圈看成二分图中右边的点,如果奶牛看上某个牛圈,就将 ...

  5. HDU 2063 过山车(二分图 && 匈牙利 && 最小点覆盖)

    嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 这是一道很经典的匈牙利问题: 把男同学看成左边点,女同学看成右边点,如果两个同学愿意同 ...

  6. HDU 1150 Machine Schedule (二分图最小点覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...

  7. 【Learning】最小点覆盖(二分图匹配) 与Konig定理证明

    (附一道例题) Time Limit: 1000 ms   Memory Limit: 128 MB Description 最小点覆盖是指在二分图中,用最小的点集覆盖所有的边.当然,一个二分图的最小 ...

  8. POJ3041 Asteroids(二分图最小点覆盖)

    Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...

  9. 四川第七届 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), ...

随机推荐

  1. startActivityForResult的用法,以及intent传递图片

    开启startActivityForResult. Intent intent = new Intent(); intent.setClass(MainActivity.this, MipcaActi ...

  2. js string对象方法

    substr(start,length) substring(start,end) 返回子串,原字符串不改变.

  3. linux下find命令详解

    Linux中find常见用法示例 ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数 ...

  4. Dom方法,解析XML文件

    Dom方法,解析XML文件的基本操作 package com.demo.xml.jaxp; import java.io.IOException; import javax.xml.parsers.D ...

  5. NTT模板(无讲解)

    #include<bits/stdc++.h>//只是在虚数部分改了一下 using namespace std; typedef long long int ll; ; ; ; ; ll ...

  6. 【转载】 unity 塔防游戏

    原文地址: Part1的地址:http://www.cnblogs.com/lcxBlog/p/6075984.html Part2的地址:http://www.cnblogs.com/lcxBlog ...

  7. Cracking The Coding Interview 1.6

    //原文: // // Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, w ...

  8. 什么是XP

    极限编程(XP)是敏捷过程中最富盛名的一个.下述这些特点使得敏捷过程能够较好地适应商业竞争环境下对小型项目提出的有效资源和有限开发时间的约束. 极限编程的有效实践 极限编程的整体开发过程 极限编程的迭 ...

  9. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法

    1.导入mysql-connector-java-5.1.26-bin.jar包,我试着把maven中自动下载下来的mysql-connector-java-5.1.26.jar包导入,还是没能解决问 ...

  10. 高级数据类型--列表[list]

    List(列表) 是 Python 中使用 最频繁 的数据类型,在其他语言中通常叫做 数组,专门用于存储 一串 信息,列表用 [] 定义,数据 之间使用 , 分隔,列表的 索引 从 0 开始. nam ...