摘要: 题意: 给出一颗有 n 个节点的树,问u 和 v 的最近公共祖先。分析: rmq:对树先进行深搜,记录深搜序列和每个序列的深度,将最近公共祖先的询问转化为区间最值问题。 tarjan:保存所有询问,在深搜的时候同时保存答案。rmq_在线算法#include<stdio.h>#include<string.h>#include<math.h>#define clr(x)memset(x,0,sizeof(x))#define maxn 10005struct node{ int to,next;}e[100000];int tot;int head[maxn] 阅读全文
posted @ 2012-09-26 19:38 'wind 阅读(249) 评论(0) 推荐(0) 编辑