LCA模板
LCALCA 是最近公共祖先问题,一般是图变成树做的问题,如有n个点m-1条边等等这样的条件,LCA有在线离线算法,这里总结的是在线算法,而且用st算法加速。
算法分析网上总结了一些博客:
http://blog.csdn.net/liangzhaoyang1/article/details/52549822
http://blog.csdn.net/insistgogo/article/details/9929103
几题的变化都不大,可见模板的通用性。
Distance Queries原题:poj 1986
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 4e4+5;
struct nod{
int to, cost;
nod(int a=0,int b=0){to = a; cost = b;}
};
int dep[maxn], se
...