| Resources | |||||
|---|---|---|---|---|---|
| CF | |||||
| CP2 | |||||
边双连通分量
重点例题 – 继续学习之前,请先尽力独立解决这道题!
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 nodeint scc; // Number of strongly connected componentsint id[MAX_N];int low[MAX_N]; // Lowest ID in node's subtree in DFS treevector<int> neighbors[MAX_N];
使用并查集
| Status | Source | Problem Name | Difficulty | Tags | ||
|---|---|---|---|---|---|---|
| Platinum | Medium | Show TagsMerging | ||||
上述题目的题解提到一种 的解法。虽然该题本身并非双连通分量问题,但我们实际上可以用并查集求出边双连通分量。
This section is not complete.
Any help would be appreciated! Just submit a Pull Request on GitHub.
(待补充讲解?)
由于这里的并查集没有按大小合并,其操作复杂度为 ,而不是 ;要改为按大小合并并不困难。
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] = xx = get(x), y = get(y);if (x == y) return 0;e[x] += e[y];e[y] = x;
练习题
| Status | Source | Problem Name | Difficulty | Tags | ||
|---|---|---|---|---|---|---|
| CEOI | Easy | Show TagsBCC | ||||
- SRM 787 1000
点双连通分量
重点例题 – 继续学习之前,请先尽力独立解决这道题!
题解
一个重要观察是:如果从顶点 到顶点 的每条路径都经过顶点 ,那么 就是一个割点。删除 会使 和 分属不同连通块,这提示我们考虑点双连通分量。
于是分为两种情况:如果 不是割点,就存在不经过它的 到 路径;如果 是割点,则需要判断它是否位于 到 的必经路径上。在原图中直接判断较困难,而在树上则容易得多。因此,我们将图转化为圆方树。
在圆方树中,每个割点和每个点双连通分量分别对应一个节点。图转化成树之后,可以利用最近公共祖先判断 到 的路径是否经过 。更多说明参见这篇文章。
代码实现
#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);
练习题
| Status | Source | Problem Name | Difficulty | Tags | ||
|---|---|---|---|---|---|---|
| CSES | Easy | Show TagsBCC | ||||
| POI | Medium | Show TagsBCC | ||||
| APIO | Medium | Show TagsBCC | ||||
| POI | Medium | Show TagsBCC | ||||
| TLE | Hard | Show TagsBCC | ||||
| CEOI | Hard | Show TagsBCC | ||||
| Platinum | Very Hard | Show TagsBCC | ||||