POJ 2446 binary maximum match

Source: Internet
Author: User

Q: I will give you an N * M graph, and then cover it with 1*2 cards. Some points cannot be covered. Check whether it can completely overwrite binary matching to find out whether the maximum match is equal to the number of points that can be covered. [Cpp] # include # Include # Include# Include # Include # Include # Include # Include # Include # Include # Include # Include # Define PI acos (-1.0) # define Max 2005 # define inf 1 <28 # define LL (x) (x <1) # define RR (x) (x <1 | 1) # define Rep (I, s, t) for (int I = (s); I <= (t); ++ I) # define ll long # define mem (a, B) memset (a, B, sizeof (a) # define mp (a, B) make_pair (a, B) using namespace std; struct kdq {int e, next;} ed [Max * 10]; int head [Max], num; void add (int s, int e) {ed [num]. e = e; ed [num]. next = head [s]; head [s] = Num ++;} int link [Max]; bool vis [Max]; int dfs (int x) {for (int I = head [x]; I! =-1; I = ed [I]. next) {int e = ed [I]. e; if (! Vis [e]) {vis [e] = 1; if (link [e] =-1 | dfs (link [e]) {link [e] = x; return 1 ;}} return 0 ;}int Map [50] [50]; int n, m, k; int mx [4] = {0, 0, 1,-1}; int my [4] = {1,-1, 0, 0}; int inmap (int x, int y) {if (x> = 1 & x <= n & y> = 1 & y <= m &&! Map [x] [y]) return 1; return 0;} int Mapnum [50] [50]; int nn = 0; void init () {mem (vis, 0); mem (head,-1); mem (link,-1); mem (Map, 0); mem (Mapnum, 0); nn = 0 ;} void build () {for (int I = 1; I <= n; I ++) {for (int j = 1; j <= m; j ++) {if (Map [I] [j] = 0) Mapnum [I] [j] = ++ nn ;}} for (int I = 1; I <= n; I ++) {for (int j = 1; j <= m; j ++) {if (! Map [I] [j]) {for (int k = 0; k <4; k ++) {int tx = I + mx [k]; int ty = j + my [k]; if (inmap (tx, ty) {add (Mapnum [I] [j], mapnum [tx] [ty]) ;}}}} int main () {while (cin >>n> m >>> k) {init (); int d = k; while (d --) {int a, B; scanf ("% d", & a, & B ); map [B] [a] = 1;} build (); int ans = 0; for (int I = 1; I <= nn; I ++) {mem (vis, 0); ans + = dfs (I);} int cnt = n * m-k; if ((Cnt & 1) | (ans! = Cnt) cout <"NO" < Else cout <"YES" < } 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.