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,-,sizeof(head));
memset(vi,,sizeof(vi));
memset(vis,,sizeof(vis));
memset(fs,,sizeof(fs));
e=;
}
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]=;
anc[u]=u;
for(i=head[u];i!=-;i=edge[i].next){
v=edge[i].v;
if(vi[v]) continue;
LCA(v);
merg(u,v);
anc[find(u)]=u;
}
vis[u]=;
for(i=;i<sz;i++){
v=que[u][i];
if(vis[v]){
int lca=anc[find(v)];
}
}
}
int main()
{
return ;
}
上一篇:【Python基础】装饰器的解释和用法


下一篇:python基础之装饰器(实例)