【图论】【二分图匹配】[Ural 1109]Conference
我的博客上的第一道Ural的题目呢。。
首先可以发现假设现在只有
#include <cstdio>
#include <cstring>
#include <algorithm>
//#include <conio.h>
using namespace std;
int endcnt;
const int MAXN = 2000;
int N, M, K;
struct node{
int v;
node *next;
}Edges[2000000+10], *adj[MAXN+10], *ecnt=Edges;
bool vis[MAXN+10];
int con[MAXN+10];
void addedge(int u, int v){
++ecnt;
ecnt->v = v;
ecnt->next = adj[u];
adj[u] = ecnt;
}
bool dfs(int u){
for(node *p=adj[u];p;p=p->next){
if(!vis[p->v]){
vis[p->v] = true;
if(!con[p->v] || dfs(con[p->v])){
con[u] = p->v;
con[p->v] = u;
return true;
}
}
}
return false;
}
int work(){
int ret = 0;
for(int i=1;i<=endcnt;i++) if(!con[i]){
memset(vis, 0, sizeof vis);
ret += dfs(i);
}
return ret;
}
void read(){
int u, v;
scanf("%d%d%d", &M, &N, &K);
for(int i=0;i<K;i++){
scanf("%d%d", &u, &v);
addedge(u, M+v);
addedge(M+v, u);
}
}
int main(){
read();
endcnt = M;
printf("%d\n", N + M - work());
return 0;
}