![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LCA
deebcjrb
这个作者很懒,什么都没留下…
展开
-
HDU-2586 How far away(LCA)模板
http://acm.hdu.edu.cn/showproblem.php?pid=2586 dis[a]为根节点到a的距离那么2个节点的最短距离就是dis[a]-dis[b]-dis[lca(a,b)]*2 参考邹老板子,存一下。 倍增法: #include<bits/stdc++.h> using namespace std; typedef long long ll; const int MX=40005; struct node { int ch,dis; }; vec原创 2020-08-17 18:47:07 · 107 阅读 · 0 评论 -
【每日一题】8月3日题目精讲—小A的最短路
https://ac.nowcoder.com/acm/problem/23482 如果没有缆车的话,就是一个利用LCA求树上任意两点距离的板子题。(有了缆车,其实还是板子题……) 有了一个缆车之后,无非就算考虑一下要不要坐缆车以及怎样坐缆车,所以:不坐缆车xy的距离就是原来的距离dist(x,y),坐缆车的话要考虑是x到u点坐缆车,还是到v点坐缆车,即dist(x,u) + dist(v,y) 和ist(x,v) + dist(u,y) #include<bits/stdc++.h> c原创 2020-08-17 18:43:46 · 91 阅读 · 0 评论