随笔分类 -  图-LCA

摘要:记节点v到根点的深度为depth[v],那么当w是v和u的最近公共祖先时,可以想让v和u在同一个深度,即让深度高的走|depth[v]-depth[u]|然后一起走, 直到遇见相同的祖先时就是最近公共祖先了。如果是计算一次的话还可以,但有很多询问时就不行了。 那么可以利用父亲节点的信息来做了,可以通 阅读全文
posted @ 2017-07-22 12:18 starry_sky 阅读(273) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2017-07-20 20:11 starry_sky 阅读(380) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2017-07-20 19:56 starry_sky 阅读(176) 评论(0) 推荐(0)