POJ3715 Two-point matching-augmentation

Source: Internet
Author: User
Tags printf
Test instructions
n individuals, there are two kinds of people, m to intimate relationship, ask at least delete several people reach no intimacy.
Ideas:
Maximum match = minimum Independent set, delete the person's impact on the maximum number of matches, if there is no impact, delete does not matter, if there is an impact on the thief delete;
similar to HDU1281;
Processing can be removed this point after the augmentation, if the search to the augmentation is not affected, can not find the augmentation is affected.
Error is a dichotomy, I want to delete two points, two sets of points can be deleted, * unilaterally deleted a *.

Error in the unconscious preference for a picture, in fact, two graphs, the picture is very independent, the status of equality and importance.

#include <bits/stdc++.h>//using namespace::std;
typedef pair<int,int> PII; #include <cstdio> #include <iostream> #include <string.h> #include <algorithm> using namespace

Std

const int N=2E2+10;
BOOL Ma[n][n];
int cx[n],cy[n],n,m;

BOOL Vis[n],col[n],deleted[n];
    BOOL Findpatex (int u) {if (Deleted[u]) return false;
            for (int i=0;i<n;i++) {if (Ma[u][i]&&!vis[i]&&!deleted[i]&&col[i]) {
            Vis[i]=true; if (cy[i]==-1| |
                Findpatex (Cy[i])) {cx[u]=i;
                Cy[i]=u;
            return true;
}}} return false;
    } bool Findpatey (int u) {if (Deleted[u]) return false;
            for (int i=0;i<n;i++) {if (Ma[u][i]&&!vis[i]&&!deleted[i]&&!col[i]) {
            Vis[i]=true; if (cx[i]==-1| |
                Findpatey (Cx[i])) {cx[i]=u;
Cy[u]=i;                return true;
}}} return false;
    } int main () {int T;
    scanf ("%d", &t);
        while (t--) {int u,v;
        scanf ("%d%d", &n,&m);
        for (int i=0;i<n;i++) scanf ("%d", &col[i]);
        memset (ma,0,sizeof (MA));
            while (m--) {scanf ("%d%d", &u,&v);
        if (Col[u]!=col[v]) ma[u][v]=ma[v][u]=1;
        } int ans=0;
        memset (cx,-1,sizeof (CX));
        memset (cy,-1,sizeof (CY));
        memset (deleted,false,sizeof (deleted)); for (int i=0;i<n;i++) {if (!col[i]&&cx[i]==-1) {memset (vis,0,si
                Zeof (VIS));
            Ans+=findpatex (i);
        }} printf ("%d", ans);
        int temp;
                    for (int i=0;i<n;i++) {if (!col[i]) {if (cx[i]!=-1) {
                    Temp=cx[i];Cx[i]=cy[temp]=-1;
                    memset (vis,0,sizeof (VIS));
                    Deleted[i]=true;
                    if (Findpatey (temp)) Deleted[i]=false;
                else printf ("%d", I); }} else {if (cy[i]!=-1) {Temp=cy
                    [i];
                    Cx[temp]=cy[i]=-1;
                    Deleted[i]=true;
                    memset (vis,0,sizeof (VIS));
                    if (Findpatex (temp)) Deleted[i]=false;
                else printf ("%d", I);
    }}} puts ("");
} 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.