以行列为点建图,每个点(x,y) 对应一条边连接x,y。二分图的最小点覆盖=最大匹配

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb(a) push(a)
#define INF 0x1f1f1f1f
#define lson idx<<1,l,mid
#define rson idx<<1|1,mid+1,r
#define PI 3.1415926535898
template<class T> T min(const T& a,const T& b,const T& c) {
return min(min(a,b),min(a,c));
}
template<class T> T max(const T& a,const T& b,const T& c) {
return max(max(a,b),max(a,c));
}
void debug() {
#ifdef ONLINE_JUDGE
#else freopen("data.in","r",stdin);
// freopen("d:\\out1.txt","w",stdout);
#endif
}
int getch() {
int ch;
while((ch=getchar())!=EOF) {
if(ch!=' '&&ch!='\n')return ch;
}
return EOF;
} const int maxn = ;
vector<int> g[maxn];
int n, m;
void Init()
{
for(int i=; i<=n; i++)
g[i].clear();
} void add(int u, int v)
{
g[u].push_back(v);
} int match[maxn];
int vis[maxn]; bool dfs(int u)
{
vis[u] = true;
for(int i = ; i < g[u].size(); i++)
{
int v = g[u][i];
int w = match[v];
if(w<||!vis[w]&&dfs(w))
{
match[u] = v;
match[v] = u;
return true;
}
}
return false;
}
int solve()
{
memset(match,-,sizeof(match));
int res = ;
for(int u=; u <= n; u++)
{
if(match[u]<)
{
memset(vis, , sizeof(vis));
if(dfs(u))
res++;
}
}
return res;
}
int main()
{
debug();
while(scanf("%d%d", &n, &m) != EOF)
{
for(int i=; i<=m; i++)
{
int u,v;
scanf("%d%d", &u, &v);
add(u, v+n);
add(v+n, u);
} printf("%d\n",solve());
}
return ;
}

POJ 3041 Asteroids 二分图匹配的更多相关文章

  1. POJ 3041 Asteroids 二分图

    原题连接:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  2. POJ 3041 Asteroids (二分图最小点覆盖)

    题目链接:http://poj.org/problem?id=3041 在一个n*n的地图中,有m和障碍物,你每一次可以消除一行或者一列的障碍物,问你最少消除几次可以将障碍物全部清除. 用二分图将行( ...

  3. poj 3041 Asteroids (二分图的最大匹配 第一题)

    题目:http://poj.org/problem?id=3041 题意:在某个n*n的空间内,分布有一些小行星,某人在里面打炮,放一枪后某一行或某一列的行星就都没了,让求最少的打炮数. 然后把每行x ...

  4. poj - 3041 Asteroids (二分图最大匹配+匈牙利算法)

    http://poj.org/problem?id=3041 在n*n的网格中有K颗小行星,小行星i的位置是(Ri,Ci),现在有一个强有力的武器能够用一发光速将一整行或一整列的小行星轰为灰烬,想要利 ...

  5. 【网络流#6】POJ 3041 Asteroids 二分图最大匹配 - 《挑战程序设计竞赛》例题

    学习网络流中ing...作为初学者练习是不可少的~~~构图方法因为书上很详细了,所以就简单说一说 把光束作为图的顶点,小行星当做连接顶点的边,建图,由于 最小顶点覆盖 等于 二分图最大匹配 ,因此求二 ...

  6. POJ 3041 Asteroids(二分图模板题)

    Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...

  7. POJ 3041 Asteroids 二分图之最大匹配

    题意:在一个网格中有若干个点,每一次可以清除一行或者一列,问最少几次可以将网格中的点全部清除. 思路:这个题是一个入门的最大匹配题(这个好像不是思路..).一般的方式就是将 行 看作集合A,列 看作集 ...

  8. poj 3041 Asteroids(二分图 *【矩阵实现】【最小点覆盖==最大匹配数】)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16379   Accepted: 8930 Descri ...

  9. POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配)

    POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配) Description Bessie wants to navigate her spa ...

随机推荐

  1. Git本地提交到远程指定分支

    git push origin master:ziranmeng2.(本地分支:远程分支)

  2. mongodb 分组查询

    数据的保存 include_once 'mDB.class.php'; $m=new mDB(); $m->setDB('mydb'); // $m->save('stu',['dept' ...

  3. 使用ssh连接远程主机

    在linux系统中,ssh是远程登录的默认工具,因为该工具的协议使用了RSA/DSA的加密算法.该工具做linux系统的远程管理是非常安全的. ssh登录远程主机(服务器)一般有两种方式:无密钥方式  ...

  4. C# Mysql You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ????

    有几年没用过MySql数据了,今天在使用C#访问MySql数据库时出现了一个小插曲. 错误提示: You have an error in your SQL syntax; check the man ...

  5. Log Buffer

    Log Buffer 一.Log Buffer的引入 Oracle有一个原则:只要是已经提交的数据,就不会丢失,保证数据库的一致性.这该如何实现?事物提交时,直接写入dbf中,效率是极低的.因为直接写 ...

  6. 26 Time Management(转)

    01. There is alway time. Time is priorities. 时间常有.时间优先. 02. Days always fill up. 时间总会有的. Only plan f ...

  7. Sublime Text 3 配置Java开发

    Sublime Text 3 配置Java开发 内嵌模式 在Sublime内部输出面板显示执行过程 配置JavaC - INSET.sublime-build 打开Sublime的包目录(选择菜单:P ...

  8. Android开发--仿微信语音对讲录音

    原文地址:http://www.2cto.com/kf/201502/378704.html 自微信出现以来取得了很好的成绩,语音对讲的实现更加方便了人与人之间的交流.今天来实践一下微信的语音对讲的录 ...

  9. 开启macbook win7触控屏右键

    开启macbook win7触控屏右键,如下图

  10. C#创建文件夹

    string path = Server.MapPath("~/DefaultImg/newDir/63/");//获取文件路径 if (!Directory.Exists(pat ...