dfs序
貌似忘写了直到要用才想起来
void dfs_(long long x)
{
in[x]=++tim;
cl[tim]=x;
v[x]=true;
for (int i=h[x];i;i=nxt[i])
{
if (v[to[i]]) continue;
dfs_(to[i]);
}
out[x]=tim;
}
倍增优化
void dfs_(int x,int fa)
{
in[x]=++tim;
q[tim]=x;
dep[x]=dep[fa]+1;
f[x][0]=fa;
v[x]=true;
for (int i=1;i<=20;i++) f[x][1]=f[f[x][i-1]][i-1];
for (int i=h[x];i;i=nxt[i])
{
if (v[to[i]]) continue;
dfs_(to[i],x);
}
out[x]=tim;
}
$\frak{msjing}$

浙公网安备 33010602011771号