讲真,为啥 C 会 RE 啊/kel
#include<stdio.h>
#include<ctype.h>
#include<string.h>
typedef int ll;
typedef long long int li;
#define MAXN 10051
#define max(x,y) (x)>(y)?(x):(y)
struct Edge{
ll to,prev,dist;
};
struct SegmentTree{
ll l,r,mx;
};
struct Edge ed[MAXN<<1];
struct SegmentTree tree[MAXN<<2];
ll test,n,tot,totd,u,v,swp;
ll last[MAXN],fa[MAXN],depth[MAXN],hv[MAXN],sz[MAXN],dfn[MAXN];
ll x[MAXN],top[MAXN],val[MAXN],from[MAXN],to[MAXN],dist[MAXN];
char ch[10];
ll read()
{
register ll num=0,neg=1;
register char ch=getchar();
while(!isdigit(ch)&&ch!='-')
{
ch=getchar();
}
if(ch=='-')
{
neg=-1;
ch=getchar();
}
while(isdigit(ch))
{
num=(num<<3)+(num<<1)+(ch-'0');
ch=getchar();
}
return num*neg;
}
void addEdge(ll from,ll to,ll dist)
{
ed[++tot].prev=last[from];
ed[tot].to=to;
ed[tot].dist=dist;
last[from]=tot;
}
void dfs(ll node,ll f)
{
ll mx=-1;
sz[node]=1,depth[node]=depth[fa[node]=f]+1;
for(register int i=last[node];i;i=ed[i].prev)
{
if(ed[i].to!=f)
{
dfs(ed[i].to,node),sz[node]+=sz[ed[i].to];
sz[ed[i].to]>mx?mx=sz[hv[node]=ed[i].to]:1;
}
}
}
void dfs2(ll node,ll link)
{
ll v;
dfn[node]=++totd,val[totd]=x[node],top[node]=link;
if(!hv[node])
{
return;
}
dfs2(hv[node],link);
for(register int i=last[node];i;i=ed[i].prev)
{
(v=ed[i].to)!=fa[node]&&v!=hv[node]?dfs2(v,v):(void)(1);
}
}
#define ls node<<1
#define rs node<<1|1
void update(ll node)
{
tree[node].mx=max(tree[ls].mx,tree[rs].mx);
}
void create(ll l,ll r,ll node)
{
tree[node].l=l,tree[node].r=r;
if(l==r)
{
return (void)(tree[node].mx=val[l]);
}
ll mid=(l+r)>>1;
create(l,mid,ls),create(mid+1,r,rs),update(node);
}
void change(ll pos,ll val,ll node)
{
if(tree[node].l==tree[node].r)
{
return (void)(tree[node].mx=val);
}
ll mid=(tree[node].l+tree[node].r)>>1;
change(pos,val,pos<=mid?ls:rs),update(node);
}
ll queryMax(ll l,ll r,ll node)
{
if(l<=tree[node].l&&r>=tree[node].r)
{
return tree[node].mx;
}
ll mid=(tree[node].l+tree[node].r)>>1;
return max((l<=mid?queryMax(l,r,ls):0),(r>mid?queryMax(l,r,rs):0));
}
#undef ls
#undef rs
ll query(ll x,ll y)
{
ll res=0;
while(top[x]!=top[y])
{
depth[top[x]]<depth[top[y]]?(swp=x,x=y,y=swp):1;
res=max(res,queryMax(dfn[top[x]],dfn[x],1)),x=fa[top[x]];
}
depth[x]>depth[y]?(swp=x,x=y,y=swp):1;
return max(res,queryMax(dfn[x]+1,dfn[y],1));
}
void solve()
{
n=read();
for(register int i=0;i<n-1;i++)
{
from[i]=read(),to[i]=read(),dist[i]=read();
addEdge(from[i],to[i],dist[i]),addEdge(to[i],from[i],dist[i]);
}
dfs(1,0);
for(register int i=0;i<n;i++)
{
depth[from[i]]>depth[to[i]]?(swp=from[i],from[i]=to[i],to[i]=swp):1;
x[to[i]]=dist[i];
}
dfs2(1,1),create(1,n,1);
while(scanf("%s",ch)==1)
{
if(ch[0]=='D')
{
return (void)(tot=totd=0,memset(last,0,sizeof(last)));
}
u=read(),v=read();
ch[0]=='C'?change(dfn[to[u-1]],v,1):(void)printf("%d\n",query(u,v));
}
}
int main()
{
test=read();
for(register int i=0;i<test;i++)
{
solve();
}
}