LCA
文章平均质量分 81
进修中的涵涵涵
acm退役选手
acm icpc 金
dota爱好者
展开
-
倍增法求LCA
一般用于求解树上两结点距离。LCA是两节点的最近公共祖先。倍增法求解LCA实际上是将上升的步数用二进制来表示,经过向上跳两结点深度的比较来确定是否可以上升,最终找到LCA。先建树维护几个数组father[][]; 记录祖先结点编号 deep[]; 记录结点深度dis[][]记录结点和祖先结点的距离 mxdeep 代表最大层数 mxdeep原创 2017-06-06 18:31:54 · 643 阅读 · 0 评论 -
倍增法求lca 模板
struct tree{ int from,to,w; tree(int ff,int tt,int ww) { from=ff;to=tt;w=ww; } tree(){}};vectorG;vectorV[M*2];int mxdeep;int father[N][30]; //记录祖先结点编号 int deep[N]; //记录结点深度int原创 2017-06-06 18:41:23 · 402 阅读 · 0 评论 -
hdu 2586 How far away ?(倍增法LCA)
How far away ?Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 15643 Accepted Submission(s): 5942Problem DescriptionThere are原创 2017-06-06 18:48:11 · 496 阅读 · 0 评论 -
HDU - 2586 How far away ?(tarjan离线做法求lca)
How far away ?Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17653 Accepted Submission(s): 6836Problem DescriptionThere are原创 2017-08-28 21:53:18 · 449 阅读 · 0 评论 -
ZOJ - 3195 Design the city(倍增法求解,tarjan离线求解)
Design the cityTime Limit: 1 Second Memory Limit: 32768 KBCerror is the mayor of city HangZhou. As you may know, the traffic system of this city is so terrible, that there are traffic jam原创 2017-09-01 02:00:38 · 536 阅读 · 0 评论 -
SPOJ - COT Count on a tree (树上路径第K小,树上主席树)
Count on a tree SPOJ - COT You are given a tree with N nodes.The tree nodes are numbered from 1 to N.Each node has an integer weight.We will ask you to perform the following operation:u原创 2017-09-01 02:14:10 · 570 阅读 · 0 评论