fork(4) download
  1. struct graph
  2. {
  3. int n;
  4. vector<vector<int>> adj;
  5.  
  6. graph(int n) : n(n), adj(n) {}
  7.  
  8. void add_edge(int u, int v)
  9. {
  10. adj[u].push_back(v);
  11. adj[v].push_back(u);
  12. }
  13.  
  14. int add_node()
  15. {
  16. adj.push_back({});
  17. return n++;
  18. }
  19.  
  20. vector<int>& operator[](int u) { return adj[u]; }
  21. };
  22.  
  23. vector<vector<int>> biconnected_components(graph &adj)
  24. {
  25. int n = adj.n;
  26.  
  27. vector<int> num(n), low(n), art(n), stk;
  28. vector<vector<int>> comps;
  29.  
  30. function<void(int, int, int&)> dfs = [&](int u, int p, int &t)
  31. {
  32. num[u] = low[u] = ++t;
  33. stk.push_back(u);
  34.  
  35. for (int v : adj[u]) if (v != p)
  36. {
  37. if (!num[v])
  38. {
  39. dfs(v, u, t);
  40. low[u] = min(low[u], low[v]);
  41.  
  42. if (low[v] >= num[u])
  43. {
  44. art[u] = (num[u] > 1 || num[v] > 2);
  45.  
  46. comps.push_back({u});
  47. while (comps.back().back() != v)
  48. comps.back().push_back(stk.back()), stk.pop_back();
  49. }
  50. }
  51. else low[u] = min(low[u], num[v]);
  52. }
  53. };
  54.  
  55. for (int u = 0, t; u < n; ++u)
  56. if (!num[u]) dfs(u, -1, t = 0);
  57.  
  58. // build the block cut tree
  59. function<graph()> build_tree = [&]()
  60. {
  61. graph tree(0);
  62. vector<int> id(n);
  63.  
  64. for (int u = 0; u < n; ++u)
  65. if (art[u]) id[u] = tree.add_node();
  66.  
  67. for (auto &comp : comps)
  68. {
  69. int node = tree.add_node();
  70. for (int u : comp)
  71. if (!art[u]) id[u] = node;
  72. else tree.add_edge(node, id[u]);
  73. }
  74.  
  75. return tree;
  76. };
  77.  
  78. return comps;
  79. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
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
Standard output is empty