随笔分类 - 图-LCA
摘要:记节点v到根点的深度为depth[v],那么当w是v和u的最近公共祖先时,可以想让v和u在同一个深度,即让深度高的走|depth[v]-depth[u]|然后一起走, 直到遇见相同的祖先时就是最近公共祖先了。如果是计算一次的话还可以,但有很多询问时就不行了。 那么可以利用父亲节点的信息来做了,可以通
阅读全文
摘要:Problem Description There are n houses in the village and some bidirectional roads connecting them. Every day peole always like to ask like this "How
阅读全文
摘要:Nearest Common Ancestors Description A rooted tree is a well-known data structure in computer science and engineering. An example is shown below: In t
阅读全文