poj1330——Nearest Common Ancestors

LCA离线算法,递归求解。详见:http://blogold.chinaunix.net/u3/105033/showart_2238641.html

伪代码:

LCA(u)
{
Make-Set (u);
ancestor[Find-Set (u)]=u;
for every child v of u
{
LCA(v);
Union (u,v);
}
color [u]=colored;
for every questioned pair (u,v)
{
if color[v]==colored
{
the lca of (u,v) is ancestor[Find-Set (v)];
}
}
}

你可能感兴趣的:(html,.net,算法)