先跑一个二分图匹配,然后一一删去匹配上的边,看能不能达到最大匹配数,不能这条边就是重要边
/*--------------------------------------------------------------------------------------*/ #include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
#define LL long long
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
/*--------------------------------------------------------------------------------------*/
using namespace std; int N,M,E,T;
const int maxn = ;
vector <int> G[maxn];
int uN;
int Mx[maxn],My[maxn];
int dx[maxn],dy[maxn];
int dis;
bool used[maxn];
bool searchP()
{
queue<int> Q;
dis = INF;
memset(dx,-,sizeof dx);
memset(dy,-,sizeof dy);
for(int i=;i<=uN;i++)
{
if(Mx[i] == -)
{
Q.push(i);
dx[i] = ;
}
}
while(!Q.empty())
{
int u = Q.front();
Q.pop();
if(dx[u] > dis) break;
int sz = G[u].size();
for(int i=;i<sz;i++)
{
int v = G[u][i];
if(dy[v] == -)
{
dy[v] = dx[u] + ;
if(My[v] == -) dis = dy[v];
else
{
dx[My[v]] = dy[v] + ;
Q.push(My[v]);
}
}
}
}
return dis != INF;
}
bool DFS(int u)
{
int sz = G[u].size();
for(int i=;i<sz;i++)
{
int v = G[u][i];
if(!used[v] && dy[v] == dx[u]+)
{
used[v] = true;
if(My[v] != - && dy[v] == dis) continue;
if(My[v] == - || DFS(My[v]))
{
My[v] = u;
Mx[u] = v;
return true;
}
}
}
return false;
}
int MaxMatch()
{
int res = ;
memset(Mx,-,sizeof Mx);
memset(My,-,sizeof My);
while(searchP())
{
memset(used,false,sizeof used);
for(int i=;i<=uN;i++)
{
if(Mx[i] == - && DFS(i)) res++;
}
}
return res/;
} vector <pair<int,int> > save;
set <pair<int,int> > st;
int cas;
int main()
{
while(~scanf("%d%d%d",&N,&M,&E))
{
uN = N+M;
for(int i=;i<maxn;i++) G[i].clear();
save.clear();
for(int i=,a,b;i<E;i++)
{
scanf("%d%d",&a,&b);
G[a].push_back(N+b);
G[N+b].push_back(a);
save.push_back(make_pair(a,N+b));
} st.clear();
int match = MaxMatch();
//printf("MaxMatch:%d\n",match);
for(int i=;i<=N;i++)
{
if(Mx[i] != -) st.insert(make_pair(i,Mx[i]));
}
int imp = ;
for(auto it = st.begin();it != st.end();it++)
{
pair<int,int> cur = *it;
//printf("delete [%d,%d]\n",cur.first,cur.second);
for(int i=;i<maxn;i++) G[i].clear();
for(int i=;i<save.size();i++) if(save[i] != cur)
{
int a = save[i].first,b = save[i].second;
G[a].push_back(b);
G[b].push_back(a);
}
if(MaxMatch() < match) imp++;
}
printf("Board %d have %d important blanks for %d chessmen.\n",++cas,imp,match);
}
}