随笔分类 - LCA
最近祖先节点
摘要:思路:裸的LCA#include#include#include#include#include#include#include#include#include#include#include#define pb push_back#define mp make_pair#define Maxn 40010#define Maxm 80002#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x > que[Maxn];void init(){ memset(head,-1,sizeof(head));
阅读全文
摘要:#include#include#include#include#include#include#include#include#include#include#include#define Maxn 100010#define Maxm 200010#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x que[Maxn];void init(){ memset(head,-1,sizeof(head)); memset(vi,0,sizeof(vi)); memset(vis,0,sizeof...
阅读全文
摘要:思路:就是个比较裸的LCA了,不过要注意的是,如果a和b的公共祖先是a,那么答案就是farther[a]。#include#include#include#include#include#include#include#include#define Maxn 300010using namespace std;int vi[Maxn],pre[Maxn];int dep[Maxn],sec[Maxn],farther[Maxn];int e,Md;char str[Maxn][70],ans[Maxn][70];vector head[Maxn];map g;void init(){ M...
阅读全文
摘要:#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define N 10010using namespace std;int dep[N],farther[N],vi[N],sec[N],Md,index[N],e,set[N];struct Edge{ int to,next;}edge[N];void addedge(int from,int to){ edge[e].to=to; edge[e].next=i
阅读全文

浙公网安备 33010602011771号