Description
lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示。当他使用某种装备时,他只能使用该装备的某一个属性。并且每种装备最多只能使用一次。 游戏进行到最后,lxhgww遇到了终极boss,这个终极boss很奇怪,攻击他的装备所使用的属性值必须从1开始连续递增地攻击,才能对boss产生伤害。也就是说一开始的时候,lxhgww只能使用某个属性值为1的装备攻击boss,然后只能使用某个属性值为2的装备攻击boss,然后只能使用某个属性值为3的装备攻击boss……以此类推。 现在lxhgww想知道他最多能连续攻击boss多少次?
题解
容易得到,只要
p
个点构成了一棵树,那么一定能够满足其中任意
代码
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 10006
using namespace std;
inline char nc(){
static char buf[100000],*i=buf,*j=buf;
return i==j&&(j=(i=buf)+fread(buf,1,100000,stdin),i==j)?EOF:*i++;
}
inline int _read(){
char ch=nc();int sum=0;
while(!(ch>='0'&&ch<='9'))ch=nc();
while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
return sum;
}
int n,fa[maxn];
bool vis[maxn];
int get(int x){return fa[x]==x?x:get(fa[x]);}
int main(){
n=_read();
for(int i=1;i<=10000;i++)fa[i]=i;
for(int i=1;i<=n;i++){
int x=_read(),y=_read();
x=get(x);y=get(y);
if(x>y)swap(x,y);
fa[x]=y;vis[x]=1;
}
for(int i=1;i<=10000;i++) if(!vis[i])return printf("%d\n",i-1),0;
return printf("10000\n"),0;
}