GYM-101915D largest group largest group

Source: Internet
Author: User

Give you a two-point chart to ask you the biggest regiment for how big

Jie Yi: Pressure DP

2:2 maximum matching of the figure

Maximal group of binary graphs = maximum independent set of complement graphs

Binary Graph Max Independent set = two point number-maximum match

//Hungary#include <bits/stdc++.h>using namespacestd;#defineN 50intUseif[n];//record whether the node in Y uses 0 to indicate no access, 1 for accessintLink[n];//Record the node of the X currently connected to the Y nodeintMat[n][n];//record the edges of the connection x and Y, if there is an edge between I and J is 1, otherwise 0intGN, GM;//number of points in X and y in a binary chartintCanintt) {inti;  for(i =1; I <= GM; i++) {                if(Useif[i] = =0&&Mat[t][i]) {Useif[i]=1; if(Link[i] = =-1||can (Link[i])) {Link[i]=T; return 1; }                }        }        return 0;}intMaxmatch () {intI, Num; Num=0; memset (Link,0xFF,sizeof(link));  for(i =1; I <= GN; i++) {memset (Useif,0,sizeof(Useif)); if(Can (i)) {num++; }        }        returnnum;}intMain () {intTCASE; scanf ("%d", &TCASE);  while(tcase--) {                intN, K; intu, v; scanf ("%d%d", &n, &k); GN= GM =N; Memset (Mat,0,sizeof(MAT));  for(inti =1; I <= K; i++) {scanf ("%d%d", &u, &v); MAT[U][V]=1; }                 for(inti =1; I <= N; i++) {                         for(intj =1; J <= N; J + +) {Mat[i][j]= Mat[i][j] ^1; }                }                intAns = n *2; Ans-=Maxmatch (); printf ("%d\n", ans); }}
View Code

GYM-101915D largest group largest group

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.