#include<bits/stdc++.h>
#define ls t[o].ch[0]
#define rs t[o].ch[1]
#define int long long
using namespace std;
const int N=500010;
const int inf=1e9;
int read() {
int x=0,f=1;
char ch=getchar();
while(ch<48||ch>57) {
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>=48&&ch<=57) {
x=(x<<3)+(x<<1)+(ch^48);
ch=getchar();
}
return x*f;
}
struct LCT {
int ch[2],fa;
int val,sum,tag;
}t[N];
bool is_rt(int o) {
int f=t[o].fa;
if(t[f].ch[0]!=o&&t[f].ch[1]!=o) return true;
else return false;
}
void rev(int o) {
if(!o) return;
swap(ls,rs);
t[o].tag^=1;
}
void push_up(int o) {
return ;
}
void push_down(int o) {
if(!t[o].tag) return ;
if(ls) rev(ls);
if(rs) rev(rs);
t[o].tag=0;
}
void push(int o) {
if(!is_rt(o)) push(t[o].fa);
push_down(o);
}
void rotate(int o) {
int f=t[o].fa;
int g=t[f].fa;
int k=t[f].ch[1]==o;
if(!is_rt(f)) {
t[g].ch[t[g].ch[1]==f]=o;
}
t[o].fa=g;
t[f].ch[k]=t[o].ch[k^1];
if(t[o].ch[k^1]) t[t[o].ch[k^1]].fa=f;
t[f].fa=o;
t[o].ch[k^1]=f;
push_up(f);
}
void splay(int o) {
int f,g;
push(o);
while(!is_rt(o)) {
f=t[o].fa;
g=t[f].fa;
if(!is_rt(f)) {
if((t[g].ch[0]==f)^(t[f].ch[0]==o)) rotate(o);
else rotate(f);
}
rotate(o);
}
push_up(o);
}
void access(int o) {
for(int i=0;o;i=o,o=t[o].fa) {
splay(o);
rs=i;
push_up(o);
}
}
void make_rt(int o) {
access(o);
splay(o);
rev(o);
}
void link(int x,int y) {
make_rt(x);
t[x].fa=y;
}
void split(int x,int y) {
make_rt(x);
access(y);
splay(y);
}
void cut(int x,int y) {
split(x,y);
if(t[y].ch[0]!=x||t[x].ch[1]) return ;
t[y].ch[0]=t[x].fa=0;
push_up(x);
}
int LCA(int x,int y) {
int lca;
access(x);
for(int i=0;y;i=y,y=t[y].fa) {
splay(y);
t[y].ch[1]=i;
push_up(y);
lca=y;
}
return lca;
}
int find_rt(int o) {
access(o);
splay(o);
while(ls) {
push_down(o);
o=ls;
}
return o;
}
signed main() {
return 0;
}
LCT 维护边权
LCT 上没有固定的父子关系,所以不方便将边权记录在点权中。
所以可以 拆边。对每条边建立一个对应点,从这条边向其两个端点连接一条边,原先的连边与删边操作都变成两次操作。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!