Question: Judge the key edge in the maximum matching of a bipartite graph, that is, remove these edges and you will not be able to get the maximum matching.
As the question shows a 100*100 graph, the enumeration + Hungary complexity is 10 ^ 8. Some are not safe. The more stable method is to use HK to change the complexity to 10 ^ 7, you can also perform some minor optimizations to save time. However, the data on this question is still relatively low, and the naked Hungary 0 ms is over.
Board games
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 1488 accepted submission (s): 856
Problem description James and gardon are playing a game: For an N * m board, place as many "cars" as possible in the grid as possible in chess ", this makes it easy for them not to attack each other, But gardon restricts that only some grids can be placed. xiaoxi easily solves this problem (see) note that the locations where vehicles cannot be placed do not affect the mutual attack of vehicles.
So gardon wants to solve a more difficult problem. While there are as many "cars" as possible, some grids in the board can be avoided. That is to say, if you don't place a car on these grids, you can also ensure that as many "cars" as possible are put down. However, if some grids are left empty, they cannot be placed as many "cars" as possible. Such grids are called important points. Gardon wants John to figure out how many important points are there. Can you solve this problem?
The input contains multiple groups of data,
The first line contains three numbers: n, m, and K (1 <n, m <= 100 1 <k <= N * m), indicating the height and width of the Board, and the number of grids that can be placed with "cars. The next K lines describe the information of all grids: each row contains two numbers x and y, indicating the position of the grid in the checker.
Output:
Board t have C important blanks for L chessmen.
Sample input3 3 4
1 2
1 3
2 1
2 2
3 3 4
1 2
1 3
2 1
3 2
Sample outputboard 1 have 0 important blks for 2 chessmen.
Board 2 have 3 important blanks for 3 chessmen.
Authorgardon
Source hangdian ACM training team training competition (VI)
Recommendlcy
# Include <stdio. h> # Include < String . H> # Include <Iostream> Using Namespace STD; # Define N 110 Bool G [N] [N]; Int Pre [N], pre1 [N]; Int N, m, K; Int Mark [N]; Int DFS ( Int S, Int P [N]) { For ( Int I = 1 ; I <= m; I ++ ){ If (MARK [I] = 1 | G [s] [I] = 0 ) Continue ; Mark [I] =1 ; If (P [I] =- 1 | DFS (P [I], p) {P [I] = S; Return 1 ;}} Return 0 ;} Int Main (){ Int Tt =1 ; While (Scanf ( " % D " , & N, & M, & K )! = EOF) {memset (G, 0 , Sizeof (G )); For ( Int I = 0 ; I <K; I ++ ){ Int X, Y; scanf ( " % D " , & X ,& Y); G [x] [Y] = 1 ;} Int Sum = 0 ; Memset (PRE, - 1 , Sizeof (Pre )); For ( Int I = 1 ; I <= N; I ++ ) {Memset (mark, 0 , Sizeof (Mark); sum + = DFS (I, pre );} Int CNT = 0 ; For ( Int I = 1 ; I <= m; I ++ ){ If (Pre [I] =- 1 ) Continue ; G [pre [I] [I] = 0 ; Int TMP = 0 ; Memset (pre1, - 1 , Sizeof (Pre1 )); For ( Int J =1 ; J <= N; j ++ ) {Memset (mark, 0 , Sizeof (Mark); TMP + = DFS (J, pre1 );} If (TMP! = Sum) CNT ++ ; G [pre [I] [I] = 1 ;} Printf ( " Board % d have % d important blanks for % d chessmen. \ n " , TT ++ , CNT, sum );} Return 0 ;}