【图论】树上启发式合并

树上启发式合并(DSU on Tree)是解决树形结构问题的有效算法,能在O(nlogn)的时间复杂度内完成操作。适用于解决竞赛编程中的特定问题,如cf600E题目。
摘要由CSDN通过智能技术生成

树上启发式合并(DSU on Tree),是一个在O(nlogn) 时间内解决许多树上问题的有力算法。

cf600E板子

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int tot,head[maxn];
struct E{
   
	int to,next;
}edge[maxn<<1];
void add(int u,int v){
   
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
int col[maxn
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值