【题解】
我们把操作倒过来做,就变成了加边而不是删边。于是用LCT维护动态加边的最小生成树就好了。同样要注意把边权变为点权。
#include<cstdio>
#include<algorithm>
#define N 200010
#define rg register
#define ls (c[u][0])
#define rs (c[u][1])
using namespace std;
int n,m,q,top,tot;
int f[N],fa[N],c[N][],rev[N],mx[N],pos[N],val[N],st[N],ans[N],num[][];
bool bro[][];
struct edge{
int u,v,dis;
}e[N];
struct question{
int opt,x,y;
}que[N];
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
inline int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
inline bool cmp(edge a,edge b){return a.dis<b.dis;}
inline int max(int x,int y){return x>y?x:y;}
inline bool isroot(int u){return c[fa[u]][]!=u&&c[fa[u]][]!=u;}
inline bool which(int u){return c[fa[u]][]==u;}
inline void pushup(int u){
pos[u]=u; mx[u]=val[u];
if(mx[ls]>mx[u]) pos[u]=pos[ls],mx[u]=mx[ls];
if(mx[rs]>mx[u]) pos[u]=pos[rs],mx[u]=mx[rs];
}
inline void pushdown(int u){
rev[u]=; rev[ls]^=; rev[rs]^=; swap(ls,rs);
}
inline void rotate(int u){
int f=fa[u],g=fa[f],wh=which(u);
if(!isroot(f)) c[g][which(f)]=u;
fa[u]=g; fa[f]=u; fa[c[u][wh^]]=f;
c[f][wh]=c[u][wh^]; c[u][wh^]=f;
pushup(f); pushup(u);
}
inline void splay(int u){
st[top=]=u;
for(rg int i=u;!isroot(i);i=fa[i]) st[++top]=fa[i];
for(rg int i=top;i;i--) if(rev[st[i]]) pushdown(st[i]);
while(!isroot(u)){
if(!isroot(fa[u])) rotate(which(u)==which(fa[u])?fa[u]:u);
rotate(u);
}
}
inline void access(int u){
for(rg int s=;u;s=u,u=fa[u]) splay(u),c[u][]=s,pushup(u);
}
inline void makeroot(int u){access(u); splay(u); rev[u]^=;}
inline int findroot(int u){
access(u); splay(u);
while(ls) u=ls; return u;
}
inline void split(int x,int y){makeroot(x); access(y); splay(y);}
inline void link(int x,int y){makeroot(x); fa[x]=y;}
inline void cut(int x,int y){
split(x,y); int t=c[y][];
if(t==x&&!c[t][]) fa[x]=,c[y][]=;
else{
while(c[t][]) t=c[t][];
if(t==x) fa[x]=,c[y][]=;
}
}
inline void build(){
sort(e+,e++m,cmp);
for(rg int i=;i<=n;i++) f[i]=i;
for(rg int i=;i<=m;i++){
val[i+n]=e[i].dis;
num[e[i].u][e[i].v]=num[e[i].v][e[i].u]=i;
}
int cnt=;
for(rg int i=;i<=m;i++){
int u=e[i].u,v=e[i].v;
if(bro[u][v]) continue;
if(find(u)!=find(v)){
cnt++; link(u,i+n); link(v,i+n);
f[find(u)]=find(v);
}
if(cnt>=n-) break;
}
}
inline void work(){
for(rg int i=q;i;i--){
int opt=que[i].opt,x=que[i].x,y=que[i].y;
if(opt==){
split(x,y); ans[++tot]=mx[y];
}
else{
int ne=num[x][y];
split(x,y);
if(e[ne].dis<mx[y]){
int oe=pos[y]-n;
cut(e[oe].u,oe+n); cut(e[oe].v,oe+n);
link(e[ne].u,ne+n); link(e[ne].v,ne+n);
}
}
}
for(rg int i=tot;i;i--) printf("%d\n",ans[i]);
}
int main(){
n=read(),m=read(),q=read();
for(rg int i=;i<=m;i++) {
e[i].u=read(),e[i].v=read(),e[i].dis=read();
}
for(rg int i=;i<=q;i++){
que[i].opt=read(); que[i].x=read(); que[i].y=read();
if(que[i].opt==)
bro[que[i].x][que[i].y]=bro[que[i].y][que[i].x]=;
}
build();
work();
return ;
}