Skip to content

Commit a4696bc

Browse files
committed
feat: update lc problem
1 parent 667a78b commit a4696bc

File tree

1 file changed

+9
-1
lines changed
  • solution/2100-2199/2123.Minimum Operations to Remove Adjacent Ones in Matrix

1 file changed

+9
-1
lines changed

solution/2100-2199/2123.Minimum Operations to Remove Adjacent Ones in Matrix/README_EN.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ No operations were done so return 0.
6868

6969
<!-- solution:start -->
7070

71-
### Solution 1
71+
### Solution 1: Hungarian Algorithm
72+
73+
We observe that if two $1$s in the matrix are adjacent, they must belong to different groups. Therefore, we can treat all $1$s in the matrix as vertices, and connect an edge between two adjacent $1$s to construct a bipartite graph.
74+
75+
Then, the problem can be transformed into finding the minimum vertex cover of a bipartite graph, which means selecting the minimum number of vertices to cover all edges. Since the minimum vertex cover of a bipartite graph equals the maximum matching, we can use the Hungarian algorithm to find the maximum matching of the bipartite graph.
76+
77+
The core idea of the Hungarian algorithm is to continuously search for augmenting paths starting from unmatched vertices until no augmenting path exists, which yields the maximum matching.
78+
79+
The time complexity is $O(m \times n)$, where $n$ and $m$ are the number of $1$s in the matrix and the number of edges, respectively.
7280

7381
<!-- tabs:start -->
7482

0 commit comments

Comments
 (0)