Lightoj 1184-marriage Media "binary graph Max Match"

Source: Internet
Author: User

Title Link: http://www.lightoj.com/volume_showproblem.php?problem=1184

According to some requirements to build a map can

Code:

#include <iostream>#include <algorithm>#include <set>#include <map>#include <string.h>#include <queue>#include <sstream>#include <stdio.h>#include <math.h>#include <stdlib.h>using namespace STD;intN, M;intp[ +][ +];intbook[ +];intmatch[ +];intDfsintu) {intI for(i =1; I <= m; i++) {if(Book[i] = =0&& P[u][i] = =1) {Book[i] =1;if(Match[i] = =0|| DFS (Match[i])) {Match[i] = u;return 1; }        }    }return 0;}structpeo{intHigintAgeintOK;} a[ the], b[ the];intMain () {intTintCases =1;scanf("%d", &t); while(t--) {scanf("%d%d", &n, &m); for(inti =1; I <= N; i++)scanf("%d%d%d", &a[i].hig, &a[i].age, &a[i].ok); for(inti =1; I <= m; i++)scanf("%d%d%d", &b[i].hig, &b[i].age, &b[i].ok);intAns =0;memset(Match,0,sizeof(match));memset(P,0,sizeof(p)); for(inti =1; I <= N; i++) for(intj =1; J <= M; J + +) {if(A[i].ok = = B[j].ok &&ABS(A[i].hig-b[j].hig) <= A&&ABS(a[i].age-b[j].age) <=5) P[i][j] =1; } for(inti =1; I <= N; i++) {memset(Book,0,sizeof(book));if(Dfs (i)) ans++; }printf("Case%d:%d\n", cases++, ans); }return 0;}

Copyright NOTICE: Reprint please indicate the source.

Lightoj 1184-marriage Media "binary graph Max Match"

Related Article

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.