同1191,什么玩意?这么大都能过,二分图匹配真是太神了。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#define maxn 10010
#define maxm 1000010
using namespace std;
int head[maxm],next[2*maxm],to[2*maxm];
int lk[maxm],vis[maxm];
int n,m,T,num,ans;
void addedge(int x,int y)
{
num++;to[num]=y;next[num]=head[x];head[x]=num;
}
bool find(int x)
{
for (int p=head[x];p;p=next[p])
if (vis[to[p]]!=T)
{
vis[to[p]]=T;
if (!lk[to[p]] || find(lk[to[p]]))
{
lk[to[p]]=x;
return 1;
}
}
return 0;
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
addedge(x,i);addedge(y,i);
}
for (int i=1;i<=10000;i++)
{
T++;
if (find(i)) ans++;
else break;
}
printf("%d\n",ans);
return 0;
}