网络流,对于每一个行星,将行星所在行到行星连一条流量为1的边,将行星到其所在列连一条流量为1的边,从源点到所有行连一条流量为1的边,将所有列到汇点都连一条流量为1的边,最大流即为答案。

  代码

 #include<cstdio>
#include<algorithm>
#define N 1000050
#define M 1000050
const int inf =0x37373737;
using namespace std;
int n,m,i,a,b;
struct Dinic {
int s, t, n, pre[N], cur[N], h[N], level[N], sign, q[N];
int cap[M], to[M], ne[M], flow, e;
void liu(int u, int v, int w) {
to[e] = v, ne[e] = h[u], cap[e] = w;
h[u] = e++;
}
void link(int u, int v, int w) {
liu(u, v, w);
liu(v, u, );
}
void init(int n) {
for (int i = ; i <= n; ++i)
h[i] = -;
e = ;
}
bool bfs() {
int L = , R = ;
fill(level, level + n, -);
sign = q[R++] = t;
level[t] = ;
while (L < R && level[s] == -) {
int c = q[L++];
for (int k = h[c]; ~k; k = ne[k]) {
if (cap[k ^ ] > && level[to[k]] == -)
level[to[k]] = level[c] + , q[R++] = to[k];
}
}
return ~level[s];
}
void push() {
int pl = inf, p, k;
for (p = t; p != s; p = to[k ^ ]) {
k = pre[p];
pl = min(pl, cap[k]);
}
for (p = t; p != s; p = to[k ^ ]) {
k = pre[p];
cap[k] -= pl;
cap[k ^ ] += pl;
if (cap[k] == )
sign = to[k ^ ];
}
flow += pl;
}
void dfs(int c) {
if (c == t)
push();
else {
for (int &k = cur[c]; ~k; k = ne[k])
if (cap[k] > && level[to[k]] + == level[c]) {
pre[to[k]] = k;
dfs(to[k]);
if (level[sign] > level[c])
return;
sign = t;
}
level[c] = -;
}
}
int run(int _s, int _t, int _n) {
s = _s, t = _t, n = _n;
flow = ;
while (bfs()) {
for (int i = ; i < n; ++i)
cur[i] = h[i];
dfs(s);
}
return flow;
}
} mf;
int main()
{
scanf("%d%d",&n,&m);
mf.init(*n+m+);
for (i=;i<=n;i++)
mf.link(,i,),mf.link(n+i,*n+m+,);
for (i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
mf.link(a,*n+i,);
mf.link(*n+i,n+b,);
}
printf("%d\n",mf.run(,*n+m+,*n+m+));
}

bzoj1741 [Usaco2005 nov]Asteroids 穿越小行星群的更多相关文章

  1. 1741: [Usaco2005 nov]Asteroids 穿越小行星群

    1741: [Usaco2005 nov]Asteroids 穿越小行星群 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 231  Solved: 166 ...

  2. BZOJ 1741: [Usaco2005 nov]Asteroids 穿越小行星群

    Description 贝茜想驾驶她的飞船穿过危险的小行星群.小行星群是一个NxN的网格(1≤N≤500),在网格内有K个小行星(1≤K≤10000). 幸运地是贝茜有一个很强大的武器,一次可以消除所 ...

  3. 【BZOJ】1741: [Usaco2005 nov]Asteroids 穿越小行星群

    [题意]给定n*n网格,有k个物品,每次可以消灭一行或一列,求消灭掉所有物品的最少操作次数. [算法]二分图最小覆盖 [题解]此题是最小覆盖模型的出处. 将物品的x-y连边建立二分图. 最小覆盖:选择 ...

  4. bzoj1741 [Usaco2005 nov]Asteroids 穿越小行星群 最小点覆盖

    链接 https://www.lydsy.com/JudgeOnline/problem.php?id=1741 思路 消除所有的小行星 每个点(x,y)只有选择x或者y才能被覆盖 二分图最小点覆盖= ...

  5. 【JZOJ1922】【Usaco 2005 NOV Gold】小行星群

    题目描述 Bessie想驾驶她的飞船穿过危险的小行星群,小行星群是一个N×N的网格(1 <= N <= 500),在网格内有K个小行星(1 <= K <= 10,000). 幸 ...

  6. [bzoj1741]穿越小行星群

    将每一行/每一列作为一个点,对于一个障碍(x,y),要么第x行和第y列的状态(是否攻击)只需要有一个就可以了,将第x行和第y列连边,就是二分图的最小点覆盖=最大匹配数. 1 #include<b ...

  7. bzoj 1741: [Usaco2005 nov]Asteroids 穿越小行星群【最大点覆盖】

    二分图最大点覆盖模型,因为对于一个点(x,y)显然只要选x或者y就好了,于是连边,跑最大匹配=最大点覆盖(不会证) #include<iostream> #include<cstdi ...

  8. [Usaco2005 Nov]Asteroids

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

  9. BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁

    2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 56  Solved: 16[S ...

随机推荐

  1. tomcat配置环境变量

    先把jdk配置好,这里不在赘述. 一.配置Tomcat环境变量 1,新建变量名:CATALINA_BASE,变量值:C:\tomcat2,新建变量名:CATALINA_HOME,变 量值:C:\tom ...

  2. 转载:C# this.invoke()作用 多线程操作UI 理解二

    Invoke()的作用是:在应用程序的主线程上执行指定的委托.一般应用:在辅助线程中修改UI线程( 主线程 )中对象的属性时,调用this.Invoke(); //测试的窗体 public class ...

  3. 1069. The Black Hole of Numbers (20)

    For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...

  4. [zt]OpenCV2.1.0的安装

    下载和安装 OpenCV 2.1.0 2.添加库文件:打开VS 2008,选择菜单:Tools->options->Projects and Solutions >VC++ Dire ...

  5. 定位position

    position : absolute | relative | fixed | static 定位:子集可以超出父级的范围,如父级蛇overflow:hidden则看不到. absolute : 绝 ...

  6. linux笔记八---------文件查找

    1.find文件查找指令 > find  目录  参数 参数值,参数 参数值.....    > find  /  -name  passwd   //从系统根目录开始递归查找name=p ...

  7. Greenplum获取表结构

    最近在折腾greenplum,遇到一个蛋疼的问题,那就是获取表结构,也就是建表语句.大家都知道在MySQL里面是非常easy的,show create table table_name 就搞定了,在g ...

  8. 织梦DEDECMS网站后台安全检测提示 加一个开关

    1.进入后台后,点击 系统->系统基本参数->添加变量: 变量名称:cfg_safecheck_switch 变量值:N 变量类型:布尔(Y/N) 参数说明:启用安全监测系统: 2.找到系 ...

  9. Maven详解之聚合与继承

    说到聚合与继承我们都很熟悉,maven同样也具备这样的设计原则,下面我们来看一下Maven的pom如何进行聚合与继承的配置实现. 一.为什么要聚合? 随着技术的飞速发展和各类用户对软件的要求越来越高, ...

  10. win2003远程桌面端口修改

    win2003远程桌面端口修改   1.改端口:简单操作步骤:打开"开始→运行",输入"regedit",打开注册表,进入以下路径:[HKEY_LOCAL_MA ...