点分治序就是每次点分治时的dfs序拼起来。点分治序的长度应该是nlogn的。
然后对于每一条路径(u,v),在出现了u的分治结构中,v总是在点分治序的一段区间里,就可以同NOI2010超级钢琴一样维护了,就是从堆中取出最大值,并把所在区间再分成两部分扔进堆里,重复m次即可。复杂度O(nlog^2n)。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int maxn=50010;
const int mlgn=900010;
int n,m,tim,a[mlgn],fz[maxn],ed[maxn],sz[maxn],st[mlgn][20],lg[mlgn];
bool vis[maxn];
struct edge
{
int t,w;
edge *next;
}*con[maxn];
struct node
{
int p,l,r,w,d;
}t[mlgn];
inline bool operator <(const node &p,