道路之径
#include<bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #define _I inline #define _R register #define ll long long #define ull unsigned long long #define mod 1000000007 #define eps 1e-5 #define INF 0x3f3f3f3f #define memset(x,y) memset(x,y,sizeof(x)) #define memcpy(x,y) memcpy(x,y,sizeof(x)) using namespace std; //char buf[1<<19],*p1=buf,*p2=buf; //#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<19,stdin),p1==p2)?EOF:*p1++) const int N=500005; int n,k,m,num; int fa[N],son[N],dep[N],top[N],p[N],size[N],fp[N],ask[N],ans[N]; int ls[N<<2],rs[N<<2],flag[N<<2],minn[N<<2]; struct note{ int x,y,z; bool operator < (const note & aa)const{ return z<aa.z; } }e[N]; struct node{ int l,r; bool operator < (const node & aa)const{ return l<aa.l; } }a[105]; vector<int>v[N]; _I int read(){ int x=0;char ch=getchar();bool f=0; while(ch>'9'||ch<'0')f|=(ch=='-'),ch=getchar(); while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); f&&(x=-x); return x; } _I void pushup(int x){ minn[x]=min(minn[x<<1],minn[x<<1|1]); } _I void pushdown(int x){ if(flag[x]==INF)return; minn[x<<1]=flag[x<<1]=min(flag[x<<1],flag[x]); minn[x<<1|1]=flag[x<<1|1]=min(flag[x<<1|1],flag[x]); flag[x]=INF; } void build(int x,int l,int r){ ls[x]=l;rs[x]=r;flag[x]=INF;minn[x]=INF; if(l==r)return; int mid=(l+r)>>1; build(x<<1,l,mid); build(x<<1|1,mid+1,r); pushup(x); } void revise(int x,int l,int r,int d){ if(ls[x]>r||rs[x]<l)return; if(l<=ls[x]&&rs[x]<=r){ minn[x]=min(minn[x],d); flag[x]=min(flag[x],d); return; } pushdown(x); revise(x<<1,l,r,d); revise(x<<1|1,l,r,d); pushup(x); } int query(int x,int k){ if(ls[x]>k||rs[x]<k)return INF; if(ls[x]==rs[x])return minn[x]; pushdown(x); return min(query(x<<1,k),query(x<<1|1,k)); } #define y v[x][i] void dfs(int x,int father,int depth){ fa[x]=father;dep[x]=depth;size[x]=1; for(_R int i=0;i<v[x].size();++i){ if(y==father)continue; dfs(y,x,depth+1); size[x]+=size[y]; if(size[y]>size[son[x]])son[x]=y; } } void dfs(int x,int tp){ fp[++num]=x;top[x]=tp;p[x]=num; if(son[x])dfs(son[x],tp); for(_R int i=0;i<v[x].size();++i){ if(y==fa[x]||y==son[x])continue; dfs(y,y); } } #undef y void add(int x,int y,int z){ int tmp=0; while(top[x]!=top[y]){ if(dep[top[x]]<dep[top[y]])swap(x,y); a[++tmp]=(node){p[top[x]],p[x]}; x=fa[top[x]]; } if(dep[x]<dep[y])swap(x,y); a[++tmp]=(node){p[y],p[x]}; sort(a+1,a+tmp+1); for(_R int i=1;i<tmp;++i)revise(1,a[i].r+1,a[i+1].l-1,z); if(1<=a[1].l-1)revise(1,1,a[1].l-1,z); if(a[tmp].r+1<=n)revise(1,a[tmp].r+1,n,z); } int main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); n=read();k=read();m=read(); for(_R int i=1,x,y;i<n;++i)x=read(),y=read(),v[x].push_back(y),v[y].push_back(x); dfs(1,0,1); dfs(1,1); build(1,1,n); for(_R int i=1;i<=k;++i)e[i].x=read(),e[i].y=read(),e[i].z=read(); sort(e+1,e+k+1); _R int tmp=0,op; for(_R int i=1;i<=m;++i){ op=read(); if(!op)++tmp,ask[i]=0; else ask[i]=read(); } for(_R int i=tmp+1;i<=k;++i)add(e[i].x,e[i].y,e[i].z); for(_R int i=m;i>=1;--i){ if(!ask[i])add(e[tmp].x,e[tmp].y,e[tmp].z),--tmp; else ans[i]=query(1,p[ask[i]]); } for(_R int i=1;i<=m;++i){ if(!ask[i])continue; if(ans[i]==INF)puts("-1"); else printf("%d\n",ans[i]); } return 0; }