PrevNext

边双连通分量

重点例题 – 继续学习之前,请先尽力独立解决这道题!

This section is not complete.

Any help would be appreciated! Just submit a Pull Request on GitHub.

(待补充讲解)

代码实现

#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5;
int timer; // Time of entry in node
int scc; // Number of strongly connected components
int id[MAX_N];
int low[MAX_N]; // Lowest ID in node's subtree in DFS tree
vector<int> neighbors[MAX_N];

使用并查集

StatusSourceProblem NameDifficultyTags
PlatinumMedium
Show TagsMerging

上述题目的题解提到一种 O(mα(n))\mathcal{O}(m\alpha(n)) 的解法。虽然该题本身并非双连通分量问题,但我们实际上可以用并查集求出边双连通分量。

This section is not complete.

Any help would be appreciated! Just submit a Pull Request on GitHub.

(待补充讲解?)

由于这里的并查集没有按大小合并,其操作复杂度为 O(log⁡n)\mathcal{O}(\log n),而不是 O(α(n))\mathcal{O}(\alpha(n));要改为按大小合并并不困难。

struct TwoEdgeCC {
struct {
vi e;
void init(int n) { e = vi(n, -1); }
int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
bool unite(int x, int y) { // set par[y] = x
x = get(x), y = get(y);
if (x == y) return 0;
e[x] += e[y];
e[y] = x;

练习题

StatusSourceProblem NameDifficultyTags
CEOIEasy
Show TagsBCC
  • SRM 787 1000

点双连通分量

重点例题 – 继续学习之前,请先尽力独立解决这道题!

题解

一个重要观察是:如果从顶点 aa 到顶点 bb 的每条路径都经过顶点 cc,那么 cc 就是一个割点。删除 cc 会使 aa 和 bb 分属不同连通块,这提示我们考虑点双连通分量。

于是分为两种情况:如果 cc 不是割点,就存在不经过它的 aa 到 bb 路径;如果 cc 是割点,则需要判断它是否位于 aa 到 bb 的必经路径上。在原图中直接判断较困难,而在树上则容易得多。因此,我们将图转化为圆方树。

在圆方树中,每个割点和每个点双连通分量分别对应一个节点。图转化成树之后,可以利用最近公共祖先判断 aa 到 bb 的路径是否经过 cc。更多说明参见这篇文章。

代码实现

#include <bits/stdc++.h>
using namespace std;
/** @return the block-cut tree of a graph */
vector<vector<int>> biconnected_components(vector<vector<int>> &g,
vector<bool> &is_cutpoint, vector<int> &id) {
int n = (int)g.size();
vector<vector<int>> comps;
vector<int> stk;

割点

重点例题 – 继续学习之前,请先尽力独立解决这道题!

Resources
CP2

可能并不完全正确

代码实现

#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2e4;
int timer;
vector<int> low, id;
vector<bool> visited, ap;
vector<vector<int>> g(NMAX);

练习题

StatusSourceProblem NameDifficultyTags
CSESEasy
Show TagsBCC
POIMedium
Show TagsBCC
APIOMedium
Show TagsBCC
POIMedium
Show TagsBCC
TLEHard
Show TagsBCC
CEOIHard
Show TagsBCC
PlatinumVery Hard
Show TagsBCC

Module Progress:

PrevNext