6802 placed the car 0x60 "graph theory" example
description
Given a chessboard M columns of N rows, some known lattice placement prohibited. The maximum number can not attack each other to put on the car to ask the board. Car on the grid, attack range and Chinese chess "car" consistent. N, M≤200.
Input Format
First row n, m, t (t indicates a prohibition has lattice)
of the second row to the behavior t + 1 x, y, represent the positions where the lattice is prohibited, for the x-row x, column y is the y ranks numbering starts at 1.
Output Format
An integer representing the maximum number of vehicles can be put.
Sample input
8 8 0
Sample Output
8
answer
The row and column node as
an element : Node row, column node only put a
0 element : no edge lines between the nodes, the nodes between the columns not
so built bipartite graph matching the maximum run time complexity \ (O ( (n + m) nm) \ )
#include<bits/stdc++.h>
#define rg register
#define il inline
#define co const
template<class T>il T read(){
rg T data=0,w=1;rg char ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-') w=-w;
for(;isdigit(ch);ch=getchar()) data=data*10+ch-'0';
return data*w;
}
template<class T>il T read(rg T&x) {return x=read<T>();}
typedef long long ll;
co int N=201;
int n,m,t,ans,fa[N];
bool a[N][N],v[N];
bool dfs(int x){
for(int y=1;y<=m;++y){
if(a[x][y]||v[y]) continue;
v[y]=1;
if(!fa[y]||dfs(fa[y])){
fa[y]=x;
return 1;
}
}
return 0;
}
int main(){
read(n),read(m),read(t);
while(t--) a[read<int>()][read<int>()]=1;
for(int i=1;i<=n;++i){
memset(v,0,sizeof v);
ans+=dfs(i);
}
printf("%d\n",ans);
return 0;
}