Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice points of the grid.

Fortunately, Bessie has a powerful weapon that can vaporize all the asteroids in any given row or column of the grid with a single shot.This weapon is quite expensive, so she wishes to use it sparingly.Given the location of all the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate all of the asteroids.

Input

* Line 1: Two integers N and K, separated by a single space. 
* Lines 2..K+1: Each line contains two space-separated integers R and C (1 <= R, C <= N) denoting the row and column coordinates of an asteroid, respectively.

Output

* Line 1: The integer representing the minimum number of times Bessie must shoot.

Sample Input

3 4
1 1
1 3
2 2
3 2

Sample Output

2

Hint

INPUT DETAILS: 
The following diagram represents the data, where "X" is an asteroid and "." is empty space: 
X.X 
.X. 
.X.

OUTPUT DETAILS: 
Bessie may fire across row 1 to destroy the asteroids at (1,1) and (1,3), and then she may fire down column 2 to destroy the asteroids at (2,2) and (3,2).

题解:二分图模板题:
参考代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<vector>
#include<map>
using namespace std;
const int maxn=;
int n,m,ok[maxn];
bool a[maxn][maxn],vis[maxn]; bool Find(int x)
{
for(int i=;i<=n;i++)
{
if(a[x][i]&&!vis[i])
{
vis[i]=true;
if(!ok[i]||Find(ok[i]))
{
ok[i]=x;
return true;
}
}
}
return false;
}
int maxP()
{
int ans=;
memset(ok,,sizeof(ok));
for(int i=; i<=n; i++)
{
memset(vis,false,sizeof(vis));
if(Find(i)) ans++;
}
return ans;
}
int main()
{
cin>>n>>m; memset(a,false,sizeof(a));
int x,y,z;
while(m--)
{
cin>>x>>y;
a[x][y]=true;
}
int ans=maxP();
printf("%d\n",ans); return ;
}

最新文章

  1. php 截取代码方法(140个字后的。)
  2. Atitit。木马病毒原理机密与概论以及防御
  3. 双向广搜 POJ 3126 Prime Path
  4. java与.net平台之间进行RSA加密验证
  5. YII学习(第一天)
  6. ssh伪登陆执行远程主机脚本命令 C程序基于ssh passwordless执行远程主机命令及基于配置文件的验证伪登陆执行命令
  7. Netty+Tomcat热部署端口占用解决办法(转)
  8. 光场相机重聚焦之三——Matlab光场工具包使用、重聚焦及多视角效果展示
  9. python正则表达式--findall、finditer方法
  10. Bigger-Mai 养成计划,前端基础学习之CSS
  11. Java 帝国之建造者模式
  12. C:malloc/calloc/realloc/alloca内存分配函数
  13. 15.Mysql中的安全问题
  14. js date 相关
  15. LR-IE录制设置
  16. jQuery动画与特效
  17. ruby关于require路径
  18. AWS文档与用户指南
  19. IntValue()方法 和 ValueOf()方法
  20. linux下安装mysql并修改密码

热门文章

  1. MyBatis两种传参方式的区别
  2. PHP 中四大经典排序算法
  3. netty源码解析(4.0)-29 Future模式的实现
  4. suseoj 1209: 独立任务最优调度问题(动态规划)
  5. docker入门篇
  6. Python 之路 Day01 笔记-什么是变量,常量等
  7. python gui tkinter快速入门教程 | python tkinter tutorial
  8. Windows 10上源码编译glog和gflags 编写glog-config.cmake和gflags-config.cmake | compile glog and glags on windows from source
  9. 在React旧项目中安装并使用TypeScript的实践
  10. Stream系列(一)Filter方法使用