struct graph
{
int n;
vector< vector< int >> adj;
graph( int n) : n( n) , adj( n) { }
void add_edge( int u, int v)
{
adj[ u] .push_back ( v) ;
adj[ v] .push_back ( u) ;
}
int add_node( )
{
adj.push_back ( { } ) ;
return n++ ;
}
vector< int > & operator[ ] ( int u) { return adj[ u] ; }
} ;
vector< vector< int >> biconnected_components( graph & adj)
{
int n = adj.n ;
vector< int > num( n) , low( n) , art( n) , stk;
vector< vector< int >> comps;
function< void ( int , int , int & ) > dfs = [ & ] ( int u, int p, int & t)
{
num[ u] = low[ u] = ++ t;
stk.push_back ( u) ;
for ( int v : adj[ u] ) if ( v ! = p)
{
if ( ! num[ v] )
{
dfs( v, u, t) ;
low[ u] = min( low[ u] , low[ v] ) ;
if ( low[ v] >= num[ u] )
{
art[ u] = ( num[ u] > 1 || num[ v] > 2 ) ;
comps.push_back ( { u} ) ;
while ( comps.back ( ) .back ( ) ! = v)
comps.back ( ) .push_back ( stk.back ( ) ) , stk.pop_back ( ) ;
}
}
else low[ u] = min( low[ u] , num[ v] ) ;
}
} ;
for ( int u = 0 , t; u < n; ++ u)
if ( ! num[ u] ) dfs( u, - 1 , t = 0 ) ;
// build the block cut tree
function< graph( ) > build_tree = [ & ] ( )
{
graph tree( 0 ) ;
vector< int > id( n) ;
for ( int u = 0 ; u < n; ++ u)
if ( art[ u] ) id[ u] = tree.add_node ( ) ;
for ( auto & comp : comps)
{
int node = tree.add_node ( ) ;
for ( int u : comp)
if ( ! art[ u] ) id[ u] = node;
else tree.add_edge ( node, id[ u] ) ;
}
return tree;
} ;
return comps;
}
c3RydWN0IGdyYXBoCnsKCWludCBuOwoJdmVjdG9yPHZlY3RvcjxpbnQ+PiBhZGo7CgoJZ3JhcGgoaW50IG4pIDogbihuKSwgYWRqKG4pIHt9CgoJdm9pZCBhZGRfZWRnZShpbnQgdSwgaW50IHYpCgl7CgkJYWRqW3VdLnB1c2hfYmFjayh2KTsKCQlhZGpbdl0ucHVzaF9iYWNrKHUpOwoJfQoKCWlud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GJ1aWxkIHRoZSBibG9jayBjdXQgdHJlZQoJZnVuY3Rpb248Z3JhcGgoKT4gYnVpbGRfdHJlZSA9IFsmXSgpCgl7CgkJZ3JhcGggdHJlZSgwKTsKCQl2ZWN0b3I8aW50PiBpZChuKTsKCgkJZm9yIChpbnQgdSA9IDA7IHUgPCBuOyArK3UpCgkJCWlmIChhcnRbdV0pIGlkW3VdID0gdHJlZS5hZGRfbm9kZSgpOwoKCQlmb3IgKGF1dG8gJmNvbXAgOiBjb21wcykKCQl7CgkJCWludCBub2RlID0gdHJlZS5hZGRfbm9kZSgpOwoJCQlmb3IgKGludCB1IDogY29tcCkKCQkJCWlmICghYXJ0W3VdKSBpZFt1XSA9IG5vZGU7CgkJCQllbHNlIHRyZWUuYWRkX2VkZ2Uobm9kZSwgaWRbdV0pOwoJCX0KCgkJcmV0dXJuIHRyZWU7Cgl9OwoKCXJldHVybiBjb21wczsKfQ==
compilation info
prog.cpp:4:2: error: ‘vector’ does not name a type
vector<vector<int>> adj;
^~~~~~
prog.cpp:20:2: error: ‘vector’ does not name a type
vector<int>& operator[](int u) { return adj[u]; }
^~~~~~
prog.cpp: In constructor ‘graph::graph(int)’:
prog.cpp:6:23: error: class ‘graph’ does not have any field named ‘adj’
graph(int n) : n(n), adj(n) {}
^~~
prog.cpp: In member function ‘void graph::add_edge(int, int)’:
prog.cpp:10:3: error: ‘adj’ was not declared in this scope
adj[u].push_back(v);
^~~
prog.cpp: In member function ‘int graph::add_node()’:
prog.cpp:16:3: error: ‘adj’ was not declared in this scope
adj.push_back({});
^~~
prog.cpp: At global scope:
prog.cpp:23:1: error: ‘vector’ does not name a type
vector<vector<int>> biconnected_components(graph &adj)
^~~~~~
stdout