题目:
题解:
寻找一个最大点集A,满足∀u,v∈V,(u,v)∉E
二分图的最大独立集=顶点数-最大匹配
代码:
#include <cstdio>
#include <iostream>
#define N 10000+5
using namespace std;
int tot,belong[N],point[N*2],v[N*2],nxt[N*2],vis[N],n;
bool a[105][105];
void addline(int x,int y)
{
++tot; nxt[tot]=point[x]; point[x]=tot; v[tot]=y;
}
bool find(int x,int k)
{
for (int i=point[x];i;i=nxt[i])
if (vis[v[i]]!=k)
{
vis[v[i]]=k;
if (!belong[v[i]] || find(belong[v[i]],k))
{
belong[v[i]]=x;
return true;
}
}
return false;
}
void floyed()
{
int i,j,k;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
for (k=1;k<=n;k++)
a[i][j]=a[i][j] || (a[i][k]&&a[k][j]);
}
int main()
{
int ans=0,m,i,u,v,maxx=0,j;
scanf("%d%d",&n,&m);
for (i=1;i<=m;i++)
scanf("%d%d",&u,&v),a[u][v]=true;
floyed();
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
if (i!=j && a[i][j]) addline(i,j);
for (i=1;i<=n;i++)
if (find(i,i)) ans++;
printf("%d",n-ans);
}