Ideas:
For images without isolated points, | maximum matching | + | minimum edge coverage | = | v |, | maximum independent set | + | minimum vertex overwrite |=| v |. For a bipartite graph, | maximum match |=| minimum vertex overwrite |. (V is the vertex set of the graph)
Implementation:
1 #include <iostream> 2 #include <cstring> 3 #include <vector> 4 using namespace std; 5 6 const int MAXN = 1005; 7 vector<int> G[MAXN]; 8 int n, m; 9 bool used[MAXN];10 int match[MAXN];11 12 bool dfs(int v)13 {14 used[v] = true;15 for (int i = 0; i < G[v].size(); i++)16 {17 int u = G[v][i];18 int w = match[u];19 if (w == -1 || !used[w] && dfs(w))20 {21 match[v] = u;22 match[u] = v;23 return true;24 }25 }26 return false;27 }28 29 int max_match()30 {31 int res = 0;32 for (int i = 1; i <= n; i++)33 {34 if (match[i] == -1)35 {36 memset(used, 0, sizeof(used));37 if (dfs(i))38 res++;39 }40 }41 return res;42 }43 44 int main()45 {46 cin >> n >> m;47 int a, b;48 for (int i = 0; i < m; i++)49 {50 cin >> a >> b;51 G[a].push_back(b);52 G[b].push_back(a);53 }54 memset(match, -1, sizeof(match));55 int ans = max_match();56 cout << ans << endl;57 cout << n - ans << endl;58 return 0;59 }
Hihocoder1127 bipartite graph 3. bipartite graph minimum vertex coverage and Maximum Independent Set