HDU 2458 Kindergarten [anti-edge of Bipartite Graph]

Source: Internet
Author: User

Question :............ Train of Thought: Calculate the least point set by the anti-key edge to overwrite the key. boys + girls-key is the answer. After Anti-edge construction, each edge represents the minimum point set that the boy and the girl do not know, after removing these vertices, all the anti-built edges are removed, and the rest is that men and women know each other .. AC code: [cpp] # include <iostream> # include <cstdio> # include <cstring> using namespace std; const int Max = 300; bool use [Max]; int link [Max]; bool map [Max] [Max]; void init () {memset (map, true, sizeof (map);} bool Dfs (int k, int m) {int I, j; for (I = 1; I <= m; I ++) {if (map [k] [I] & use [I]) {use [I] = false; if (! Link [I] | Dfs (link [I], m) {link [I] = k; return true ;}} return false ;} int MaxMatch (int n, int m) {int I, j; int ans = 0; memset (link, 0, sizeof (link); for (I = 1; I <= n; I ++) {memset (use, true, sizeof (use); if (Dfs (I, m) ans ++;} return ans;} int main () {int I, j, n, m, k; int ncase = 1; while (scanf ("% d", & n, & m, & k) & (n + k + m) {init (); while (k --) {scanf ("% d", & I, & j ); map [I] [j] = false;} printf ("Case % d:", ncase ++); printf ("% d \ n ", n + m-MaxMatch (n, m);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.