poj 1986 Distance Queries(LCA)


poj 1986 Distance Queries


和此题一样


#include
#include
#include
#include
using namespace std;
#define MAXN 40005

struct tnode
{
    int v,d;
    tnode(int v=0,int d=0):v(v),d(d){}
};
struct qnode
{
    int v,id;
    qnode(int v=0,int id=0):v(v),id(id){}
};
struct qqnode
{
    int u,v,anc;
    qqnode(int u=0,int v=0):u(u),v(v){}
}qq[MAXN];
vector t[MAXN];
vector q[MAXN];
int dis[MAXN],fa[MAXN];
bool vis[MAXN];
int n,m;

void ini()
{
    for(int i=0;i<=n;i++)
    {
        t[i].clear();
        q[i].clear();
        fa[i]=i;
        vis[i]=false;
    }
}
int find(int x) {return x==fa[x]?x:fa[x]=find(fa[x]);}
void lca(int u)
{
    vis[u]=true;
    for(int i=0;i


你可能感兴趣的:(LCA)