RT,莫名其妙的有几个点的数据读不进去……
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define mem(l,val) memset((l),(val),(sizeof(l)))
using namespace std;
const int INF = 2147483647;
const int S = 1e5+5;
int n,m,x,a[S],fa[S];
__gnu_pbds::priority_queue<pair<int,int>,greater<pair<int,int> > > pq[S];
inline int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(int argc,char *argv[])
{
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;++i)
{
fa[i] = i;
scanf("%d",&x);
pq[i].push(make_pair(x,i));
}
while(m--)
{
scanf("%d",&x);
switch(x)
{
case 1:
int xx,yy,fx,fy;
scanf("%d%d",&xx,&yy);
fx = find(xx),fy = find(yy);
if(!a[xx] || a[yy] || fx == fy) pq[fx].join(pq[fy]),fa[fy] = fx;
break;
default:
int xxx,fxx;
scanf("%d",&xxx);
fxx = find(xxx);
if(a[xxx]) {puts("-1");continue;}
a[pq[fxx].top().second] = 1;
printf("%d\n",pq[fxx].top().first);
pq[fxx].pop();
}
}
return 0;
}