Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Output The biconnected Component of an undirected graph
- 0 - base indexing
- use init first. adde then.
- bc[i] = # of i biconnected component.
- */
- #include <bits/stdc++.h>
- #define FO(i,a,b) for (int i = (a); i < (b); i++)
- #define sz(v) int(v.size())
- using namespace std;
- struct bcc {
- vector<vector<int> > u;
- vector<int> bc, lo, ind,SZ;
- vector<vector<int> > G;
- int T, m, n;
- void init(int n_) {
- n = n_; m = 0; T = 0;
- u.clear(); u.resize(n);
- G.clear(); G.resize(n);
- bc.assign(n,-1);
- lo.assign(n,-1);
- SZ.assign(n,0);
- ind.assign(n,-1);
- }
- void adde(int i, int j) {
- u[i].push_back(j);
- u[j].push_back(i);
- }
- vector<int> stk;
- void go(int i, int p) {
- ind[i] = lo[i] = ++T;
- stk.push_back(i);
- for (int j : u[i]) if (j != p) {
- if (ind[j] == -1) {
- go(j, i);
- lo[i] = min(lo[i],lo[j]);
- } else {
- lo[i] = min(lo[i],ind[j]);
- }
- } else p = -1;
- if (ind[i] == lo[i]) {
- int t;
- do {
- t = stk.back(); stk.pop_back();
- bc[t] = m;
- } while (t != i);
- m++;
- }
- }
- void dobcc() {
- FO(i,0,n) if (ind[i] == -1) go(i,-1);
- }
- };
Add Comment
Please, Sign In to add comment