Tarjan 离线算法LCA

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Maxn 100010
#define Maxm 200010
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 0x7fffffff
#define Mod 1000000007
using namespace std;
int head[Maxn],vi[Maxn],e,fs[Maxn],fa[Maxn],anc[Maxn],vis[Maxn];
struct Edge{
    int u,v,next;
}edge[Maxm];
vector<int> que[Maxn];
void init()
{
    memset(head,-1,sizeof(head));
    memset(vi,0,sizeof(vi));
    memset(vis,0,sizeof(vis));
    memset(fs,0,sizeof(fs));
    e=0;
}
void add(int u,int v)
{
    edge[e].u=u,edge[e].v=v,edge[e].next=head[u],head[u]=e++;
    edge[e].u=v,edge[e].v=u,edge[e].next=head[v],head[v]=e++;
}
int find(int x)
{
    if(x!=fa[x])
        fa[x]=find(fa[x]);
    return fa[x];
}
void merg(int a,int b)
{
    int x=find(a);
    int y=find(b);
    if(fs[y]<=fs[x])
        fa[y]=x,fs[x]+=fs[y];
    else fa[x]=y,fs[y]+=fs[x];
}
void LCA(int u)
{
    int i,v,sz;
    sz=que[u].size();
    vi[u]=1;
    anc[u]=u;
    for(i=head[u];i!=-1;i=edge[i].next){
        v=edge[i].v;
        if(vi[v]) continue;
        LCA(v);
        merg(u,v);
        anc[find(u)]=u;
    }
    vis[u]=1;
    for(i=0;i<sz;i++){
        v=que[u][i];
        if(vis[v]){
            int lca=anc[find(v)];
        }
    }
}
int main()
{
    return 0;
}

 

posted @ 2013-09-01 15:37  fangguo  阅读(200)  评论(0编辑  收藏  举报