POJ 3692 – Kindergarten 二分圖的最大獨立點集

來源:互聯網
上載者:User

                    題意:

                              在一個幼兒園中,所有的女孩互相認識..所有的男孩互相認識..有些女孩和男孩認識..現在要選出一些人來搞活動.要求他們都互相認識..問最多能選出多少人..

                    題解:

                              對一個無向圖來說,獨立點集就是選出若干個點使得他們之間兩兩都不可達...二分圖的最大獨立點集就是選出最多的點,使它們兩兩間都沒有邊...解法是用兩側點的總數減去二分圖最大匹配數....對於本題..正著求麻煩..把邊反過來建..不認識的的建邊..求出的最大獨立點集就是互相都認識的了...

Program:

#include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<stack>#include<string.h>#include<queue>#define ll long long#define esp 1e-5#define MAXN 202#define MAXM 50000000#define oo 100000007using namespace std;  int G,B,match[MAXN];bool used[MAXN],arc[MAXN][MAXN];bool dfs(int x){       int i,j;       for (i=1;i<=B;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 i,ans=0;       memset(match,0,sizeof(match));       for (i=1;i<=G;i++)       {              memset(used,false,sizeof(used));              ans+=dfs(i);       }       return ans;}int main()  {                int x,y,M,cases=0;        while (~scanf("%d%d%d",&G,&B,&M) && (G || B))       {               memset(arc,true,sizeof(arc));               while (M--)               {                       scanf("%d%d",&x,&y);                       arc[x][y]=false;               }               printf("Case %d: %d\n",++cases,G+B-getmax());       }       return 0;  }  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.