ContinueLib

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Continue765/ContinueLib

:heavy_check_mark: BlockCutTree
(graph/components/block_cut_tree.hpp)

BlockCutTree

定义于头文件 block_cut_tree.hpp

struct BlockCutTree;

构造无向图的圆方树,$O(n + m)$。

成员变量

成员变量 说明
int n 原图点数
int tot 圆方树点数,即圆点与方点之和
Undigraph<int> tree 圆方树,点 $0, \dots, n - 1$ 为原图的圆点,其余为方点

成员函数

构造

成员函数 说明
template <typename T> BlockCutTree(const Undigraph<T>& g) 构造 g 的圆方树,$O(n + m)$

查询

成员函数 说明
bool isCut(int u) const 原图的点 u 是否为割点,$O(1)$

示例

Undigraph<int> g(4);
g.add(0, 1);
g.add(1, 2);
g.add(2, 0);
g.add(2, 3);

BlockCutTree bct(g);
bool cut = bct.isCut(2);
int k = bct.tot;
for (auto [v, id] : bct.tree[2]) {
    int u = v;
}

Depends on

Verified with

Code

#pragma once
#include <graph/graph.hpp>

struct BlockCutTree {
    int n, tot;
    Undigraph<int> tree;

    BlockCutTree() {}
    template <typename T>
    BlockCutTree(const Undigraph<T>& g) : n(g.n), tree(n) {
        vector<int> dfn(n, -1), low(n), stk;
        int cur = 0;
        auto dfs = [&](auto&& self, int u) -> void {
            dfn[u] = low[u] = cur++;
            stk.push_back(u);
            for (auto [v, id] : g[u]) {
                if (dfn[v] == -1) {
                    self(self, v);
                    low[u] = min(low[u], low[v]);
                    if (low[v] >= dfn[u]) {
                        int b = tree.n++;
                        tree.adj.emplace_back();
                        tree.add(u, b);
                        int x;
                        do {
                            x = stk.back();
                            stk.pop_back();
                            tree.add(x, b);
                        } while (x != v);
                    }
                } else {
                    low[u] = min(low[u], dfn[v]);
                }
            }
        };
        for (int u = 0; u < n; u++) {
            if (dfn[u] == -1) {
                dfs(dfs, u);
                stk.pop_back();
            }
        }
        tot = tree.n;
    }

    bool isCut(int u) const {
        return tree[u].size() > 1;
    }
};
Back to top page