根據題目描述,什麼是重要點?在求出最大匹配後,進行枚舉,依次刪邊,看最大匹配數會不會發生改變,改變的話,那麼該點就是重要點。
#include#include #include #include #include #include #define init(a) memset(a,0,sizeof(a)) #define PI acos(-1,0) using namespace std; const int maxn = 110; const int maxm = 10100; #define lson left, m, id<<1 #define rson m+1, right, id<<1|1 #define min(a,b) (a>b)?b:a #define max(a,b) (a>b)?a:b int mar[maxn][maxn]; int G[maxn][maxn]; int line[maxn]; bool vis[maxn]; int n,m,k; int DFS(int u) { for(int v = 1;v<=m;v++) { if(G[u][v] && !vis[v]) { vis[v] = 1; if(line[v] == -1 || DFS(line[v])) { line[v] = u; return 1; } } } return 0; } int K_M() { int ans = 0; memset(line,-1,sizeof(line)); for(int i = 1;i<=n;i++) { init(vis); ans += DFS(i); } return ans; } int main() { int x[maxm],y[maxm],C = 0; while(scanf(%d%d%d,&n,&m,&k)!=EOF) { C++; init(G); for(int i = 1;i<=k;i++) { scanf(%d%d,&x[i],&y[i]); G[x[i]][y[i]] = 1; } int ans = K_M(); int num = 0; for(int i = 1;i<=k;i++) { G[x[i]][y[i]] = 0;//刪邊 if(ans > K_M()) num++; G[x[i]][y[i]] = 1;//恢復 } printf(Board %d have %d important blanks for %d chessmen. ,C,num,ans); } return 0; }