bzoj3282 tree 解題報告

2021-07-10 19:40:43 字數 1229 閱讀 5188

這題是個lct裸題,但是我down的時候down到了root。。導致跪了,調了兩天。。

#include

#include

using

namespace

std;

#include

#include

const

int n=3e5+5,m=3e5+5;

struct lslct[n];

void out(int node)\n",node,lct[node].ch[0],lct[node].ch[1],lct[node].fa,lct[node].v,lct[node].sum);

}void pushup(int node)

void paint(int node)

}void pushdown(int node)

}bool is_top(int node)

intstack[n];

void down(int node)

void rot(int node)

void splay(int node)

}void discon(int node)

#include

void access(int node)

pushup(node);

/*if(node==9456)

if(flag==2)

void makeroot(int node)

void getchain(int u,int v)

void link(int from,int to)

void cut(int from,int to)

void in(int &x)

int main()

int opt,x,y;

while(m--)

break;

case

2: getchain(x,y);

if(lct[x].fa==y&&lct[x].ch[1]==0)cut(x,y);

break;

case

3: splay(x);

lct[x].v=lct[x].sum=y;

break;}}

}

總結:

①down的時候要down到top。

②調樹上問題的時候很有可能會被鏈的資料卡飛;所以自己構造乙個鏈試一試。

bzoj 2870 最長道路tree

題目 邊分治邊分和點分相比就是找到一條重心邊,考慮所有經過這條邊的路徑,之後斷開這條邊分成兩個聯通塊,繼續分治 由於每次分治重心是一條邊,所以只會產生兩個聯通塊,考慮兩個聯通塊顯然要比像點分那樣考慮多個聯通塊容易 但是邊分有乙個問題,就是遇到菊花圖就自閉了,複雜度變成了 o n 2 我們注意到邊分的...

BZOJ2870 最長道路tree

題解 子樹分治的做法可以戳這裡 可是碼量。這裡介紹另一種好寫又快的方法。我們還是一顆一顆子樹處理,處理完乙個子樹,考慮列舉最小值。如果我們現在處理到了x節點,它到根的min為w。那麼我們就可以在以前的資訊中找出min w且長度最長的一條鏈並且用它和該鏈合併,同時更新答案。這個顯然可以用樹狀陣列搞。處...

bzoj4987 Tree 樹形揹包

description 從前有棵樹。找出k k 個點a1 a2,ak role presentation style position relative a1,a2,aka 1,a2 a k。使得 dis ai,a i 1 1 i k 1 di s ai ai 1 1 i k 1 最小solutio...