Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c318204

Browse files
Block Cut Tree correction
1 parent 829d3e2 commit c318204

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

‎Library/Grafos/BlockCutTree.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <bits/stdc++.h>
22
using namespace std;
3-
#define pii pair<int,int>
43

54
struct BlockCutTree {
65
vector<vector<int>> g, tree, comp;
@@ -17,34 +16,21 @@ struct BlockCutTree {
1716
for(int u=0; u<n; u++, chd=0) if(pre[u] == -1) //if graph is disconected
1817
tarjan(u, -1), makeComp(-1); //find cut vertex and make components
1918

20-
for(int i=0, ct=1; i<comp.size(); i++, ct=1){ //remove components with only cuts
21-
for(auto u : comp[i]) ct &= cut[u];
22-
if(ct) swap(comp[i], comp.back()), comp.pop_back(), i--;
23-
}
24-
2519
for(int u=0; u<n; u++) if(cut[u]) comp.emplace_back(1, u); //create cut components
20+
for(int i=0; i<comp.size(); i++) //mark id of each node
21+
for(auto u : comp[i]) id[u] = i;
2622

27-
for(int i=0; i<comp.size(); i++) //mark id of each node
28-
for(auto u : comp[i])
29-
id[u] = i;
30-
31-
tree.resize(comp.size()); //creates tree (looking only edges from cut points)
32-
pre.assign(comp.size(), 1);
33-
34-
for(int u=0; u<n; u++) if(cut[u]){
35-
for(auto v : g[u]) if(pre[id[v]] && (!cut[v] || u<v)) addt(id[u], id[v]), pre[id[v]]=0;
36-
for(auto v : g[u]) pre[id[v]] = 1;
37-
}
23+
tree.resize(comp.size());
24+
for(int i=0; i<comp.size(); i++)
25+
for(auto u : comp[i]) if(id[u] != i)
26+
tree[i].push_back(id[u]),
27+
tree[id[u]].push_back(i);
3828
}
3929
private:
4030
vector<int> pre, low;
41-
vector<pii> st;
31+
vector<pair<int, int>> st;
4232
int n, clk = 0, chd=0, ct, a, b;
43-
void addt(int u, int v){
44-
tree[u].push_back(v);
45-
tree[v].push_back(u);
46-
}
47-
33+
4834
void makeComp(int u){
4935
comp.emplace_back();
5036
do {
@@ -71,13 +57,14 @@ struct BlockCutTree {
7157
}
7258
};
7359

60+
7461
/*LATEX_DESC_BEGIN***************************
7562
Block Cut Tree - BiConnected Component
7663
BlockCutTree bcc(n);
7764
bcc.addEdge(u, v);
7865
bcc.build();
7966
80-
bcc.tree -> graph of BlockCutTree
67+
bcc.tree -> graph of BlockCutTree (tree.size() <= 2n)
8168
bcc.id[u] -> componet of u in the tree
8269
bcc.cut[u] -> 1 if u is a cut vertex; 0 otherwise
8370
bcc.comp[i] -> vertex of comp i (cut are part of multiple comp)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /