边双板子
Cvector g(n + 1, vector<PII>());
stack<int>stk;
vector<bool>in_stk(n + 2);
int dcc_cnt = 0, timestamp = 0, root = 0;
vector<int>dfsn(n + 2), low(n + 2), Size(n + 2), id(n + 2);
auto tarjan = [&](auto self, int u, int f) -> void{
low[u] = dfsn[u] = ++ timestamp;
stk.push(u);
in_stk[u] = true;
for(auto [v, edge] : g[u]){
if(edge == (f ^ 1))continue;
if(!dfsn[v]){
self(self, v, edge);
low[u] = min(low[u], low[v]);
}else low[u] = min(low[u], dfsn[v]);
}
if(dfsn[u] == low[u]){
int y;
++ dcc_cnt;
do{
y = stk.top();
in_stk[y] = false;
id[y] = dcc_cnt;
stk.pop();
}while(y != u);
}
};
for(int i = 1; i <= m; ++ i){
int u, v;
cin >> u >> v;
g[u].emplace_back(v, i << 1);
g[v].emplace_back(u, i << 1 | 1);
}
for(int i = 1; i <= n; ++ i){
if(!dfsn[i])tarjan(tarjan, i, 0);
}
vector G(dcc_cnt + 2, vector<int>());
vector<int>dep(dcc_cnt + 2);
vector fa(dcc_cnt + 5, vector<int>(21));
for(int i = 1; i <= n; ++ i){
for(auto [v, _] : g[i]){
if(id[i] != id[v]){
G[id[i]].emplace_back(id[v]);
}
}
}
auto dfs1 = [&](auto self, int u, int f) -> void{
dep[u] = dep[f] + 1;
fa[u][0] = f;
for(int i = 1; i <= 20; ++ i){
fa[u][i] = fa[fa[u][i - 1]][i - 1];
}
for(auto v : G[u]){
if(v == f)continue;
self(self, v, u);
}
};
for(int i = 1; i <= dcc_cnt; ++ i)
if(!dep[i])dfs1(dfs1, i, 0);
auto LCA = [&](int x, int y) -> int {
if(dep[x] < dep[y]) swap(x, y);
for(int i = 20; i >= 0; --i) {
if(dep[x] - (1LL << i) >= dep[y]) {
x = fa[x][i];
}
}
if(x == y) return x;
for(int i = 20; i >= 0; --i) {
if(fa[x][i] != fa[y][i]) {
x = fa[x][i];
y = fa[y][i];
}
}
return fa[x][0];
};