Given a grid, some grid coordinates now contain an minor. A weapon can penetrate one row or one column of the minor. How many times can this weapon be used to destroy all the minor planets.
Solution: as long as each vertex is overwritten by rows or columns, you can match the rows and columns where a certain vertex is located, and the problem is converted to a minimum vertex overwrite, this ensures that each edge has a vertex in the vertex set. That is, each minor can be overwritten by its row or column.
The Code is as follows:
# Include <iostream> # include <cstring> # include <cstdio> # include <cstdlib> # include <algorithm> using namespace STD; int n, m; char G [505] [505], vis [505]; int match [505]; int path (int u) {for (INT I = 1; I <= N; ++ I) {If (! G [u] [I] | Vis [I]) continue; vis [I] = 1; if (! Match [I] | path (Match [I]) {match [I] = u; return 1 ;}} return 0 ;} int query () {int ret = 0; memset (match, 0, sizeof (MATCH); For (INT I = 1; I <= N; ++ I) {memset (VIS, 0, sizeof (VIS); RET + = path (I);} return ret;} int main () {int A, B; while (scanf ("% d", & N, & M )! = EOF) {for (INT I = 0; I <m; ++ I) {scanf ("% d", & A, & B ); G [a] [B] = 1; // the row-column matching diagram. Finally, obtain a minimum vertex overwrite.} printf ("% d \ n", query ());} return 0 ;}