HDU 1281 board game (two-point matching and edge deletion)
Based on the topic description, what is important? After finding the maximum match, perform enumeration and delete the edge in sequence to see if the maximum match number will change. If it changes, this is an important point.
# Include
# Include
# Include
# Include
# Include
# Define init (a) memset (a, 0, sizeof (a) # define PI acos (-110) using namespace std; const int maxn =; 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: bint 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, & n, & m, & k )! = EOF) {C ++; init (G); for (int I = 1; I <= k; I ++) {scanf (% 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; // Delete the edge if (ans> K_M () num ++; G [x [I] [y [I] = 1; // restore} printf (Board % d have % d important blanks for % d chessmen ., c, num, ans);} return 0 ;}