【題目鏈接】http://www.lydsy.com/JudgeOnline/problem.php?id=1854
【解題思路】二分圖匹配順序增廣即可,還有神奇的並查集做法,詳見黃學長博客(http://hzwer.com/2950.html)
【呆馬(並查集)】
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iostream>
const int N=1e4+10;
using namespace std;
int n,x,y,i,fa[N],f[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
freopen("bzoj1854.in","r",stdin);
freopen("bzoj1854.out","w",stdout);
scanf("%d\n",&n);
for (i=1;i<=10000;i++) fa[i]=i;
for (i=1;i<=n;i++)
{
scanf("%d%d\n",&x,&y);
x=find(x);
y=find(y);
if (x==y) f[x]=1;
else
{
if (x>y) swap(x,y);
fa[x]=y;
f[x]=1;
}
}
for (i=1;i<=n+1;i++)
if (!f[i])
{
printf("%d",i-1);
return 0;
}
fclose(stdin);
fclose(stdout);
}