HDOJ 1498-50 years, 50 colors water bipartite graph .. bipartite graph minimum vertex Overwrite

Source: Internet
Author: User

Question:

In a matrix of n * n (n <= 100) .. each lattice is filled with a color balloon (the color is measured in numbers 1 ~ 50)... each operation is to remove one row or one column of balloons with the same color. After k operations, ask which balloons of the same color still exist...

Question:

Separate each color... side (x, y ).... because for a balloon (x, y ).. as long as x is used or y is used .. then this balloon will be eliminated... how many points should I use to convert a question .. overwrite all edges .. that is, the classic bipartite graph least Point Coverage problem... it is equivalent to finding the maximum number of matching for a bipartite graph...

Program:

#include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<stack>#include<queue>#define ll long long#define MAXN 105using namespace std;int n,match[MAXN];bool arc[MAXN][MAXN],inmap[MAXN],used[MAXN],s[MAXN][MAXN]; bool dfs(int x){       int i;       for (i=1;i<=n;i++)          if (arc[x][i] && !used[i])          {                 used[i]=true;                 if (!match[i] || dfs(match[i]))                 {                       match[i]=x;                       return true;                 }          }              return false; }int getmax(){       int sum=0;       memset(match,0,sizeof(match));       for (int i=1;i<=n;i++)       {               memset(used,false,sizeof(used));               sum+=dfs(i);       }       return sum;}int main(){       int i,j,k,ans;       bool f;        while (~scanf("%d%d",&n,&k) && n)       {               memset(inmap,false,sizeof(inmap));               for (i=1;i<=n;i++)                  for (j=1;j<=n;j++)                     scanf("%d",&s[i][j]),inmap[s[i][j]]=true;               f=false;               for (int t=1;t<=50;t++)                  if (inmap[t])                  {                         memset(arc,false,sizeof(arc));                         for (i=1;i<=n;i++)                            for (j=1;j<=n;j++)                                if (s[i][j]==t) arc[i][j]=true;                         if (getmax()>k)                          {                                 if (!f) printf("%d",t);                                    else printf(" %d",t);                                 f=true;                         }                  }               if (!f) printf("-1");               printf("\n");        }       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.