摘要:题目大意:一棵树,然后m个询问,每个询问有k个点,然后判断是否有一条路,要求这k个点要么在这条路上,要么和这条路相距为1. 题解:刚开始的思路是这样的,这条路的终点肯定是深度最深的那个点,然后用BFS找到从1到终点的路线,然后在对路径上的点和与路径直接相连的点进行判断,看这k个点是否都在其中,然后就
阅读全文
随笔分类 - 树论---LCA
摘要:题目大意:一棵树,然后m个询问,每个询问有k个点,然后判断是否有一条路,要求这k个点要么在这条路上,要么和这条路相距为1. 题解:刚开始的思路是这样的,这条路的终点肯定是深度最深的那个点,然后用BFS找到从1到终点的路线,然后在对路径上的点和与路径直接相连的点进行判断,看这k个点是否都在其中,然后就
阅读全文
摘要:A rooted tree is a well-known data structure in computer science and engineering. An example is shown below: In the figure, each node is labeled with
阅读全文
摘要:There are n houses in the village and some bidirectional roads connecting them. Every day peole always like to ask like this "How far is it if I want
阅读全文
摘要:Language: Default Closest Common Ancestors Time Limit: 2000MS Memory Limit: 10000K Total Submissions: 24653 Accepted: 7648 Description Write a program
阅读全文
摘要:例题:http://poj.org/problem?id=1986 POJ1986 Distance Queries Language: Default Distance Queries Time Limit: 2000MS Memory Limit: 30000K Total Submission
阅读全文
摘要:https://www.luogu.org/problemnew/solution/P3379 LCA叫做最短公共祖先,用来求距离树上两个节点最近的公共点; 常用倍增算法:
阅读全文
|