现场YY了一个并查集,结果t了一个点

P2342 [USACO04OPEN] Cube Stacking G【重题,见 P5092】

垃圾
by Achtoria @ 2019-05-08 12:49:42


对不起,被机惨了
by Achtoria @ 2019-05-08 12:50:17


@[Panthera_AFO](/space/show?uid=55868) 路径压缩
by saxiy @ 2019-08-27 18:38:16


@[Panthera_AFO](/space/show?uid=55868) ```cpp int find(int x) { if(x == fa[x]) return x; int f = find(fa[x]); di[x] += di[fa[x]]; return fa[x] = f; } ``` 不用管num,第 $x$ 堆的并查集根一定是 $x$ ,查num时先查遍根就好了。
by saxiy @ 2019-08-27 18:40:49


$union$ 这么写: ```cpp a = find(a), b = find(b); dis[a] += num[b]; num[b] += num[a]; fa[a] = b; ```
by saxiy @ 2019-08-27 18:42:08


|