# BZOJ 1455 罗马游戏 左偏树

1.将两个点所在集合合并

2.将一个点所在集合的最小的点删除并输出权值

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define M 1001001
using namespace std;
struct abcd{
abcd *ls,*rs;
int h,pos,score;
abcd(int x,int y);
}*null=new abcd(0,0x3f3f3f3f),*tree[M];
abcd :: abcd(int x,int y)
{
ls=rs=null;
if(!null) h=-1;
else h=0;
pos=x;score=y;
}
abcd* Merge(abcd *x,abcd *y)
{
if(x==null) return y;
if(y==null) return x;
if(x->score>y->score)
swap(x,y);
x->rs=Merge(x->rs,y);
if(x->ls->h<x->rs->h)
swap(x->ls,x->rs);
x->h=x->rs->h+1;
return x;
}
int n,m;
int fa[M];
int Find(int x)
{
if(!fa[x]||fa[x]==x)
return fa[x]=x;
return fa[x]=Find(fa[x]);
}
void Unite(int x,int y)
{
x=Find(x);y=Find(y);
if(x==y) return ;
fa[x]=y;
tree[y]=Merge(tree[x],tree[y]);
}
int main()
{

//freopen("1455.in","r",stdin);
//freopen("1455.out","w",stdout);

int i,x,y;
char p[10];
cin>>n;
for(i=1;i<=n;i++)
scanf("%d",&x),tree[i]=new abcd(i,x);
cin>>m;
for(i=1;i<=m;i++)
{
scanf("%s",p);
if(p[0]=='M')
{
scanf("%d%d",&x,&y);
continue;
Unite(x,y);
}
else
{
scanf("%d",&x);
{
puts("0");
continue;
}
x=Find(x);
printf("%d\n",tree[x]->score);