|
9 | 9 | //! int count_edges = 0; |
10 | 10 | //! rep (i, 0, sz(nodes) - 1) { |
11 | 11 | //! seen[nodes[i]] = 1; |
12 | | -//! for (int v : adj[nodes[i]]) if (!seen[v]) { |
13 | | -//! // edge nodes[i] <=> v is in current BCC |
| 12 | +//! for (int u : adj[nodes[i]]) if (!seen[u]) { |
| 13 | +//! // edge nodes[i] <=> u is in current BCC |
14 | 14 | //! count_edges++; |
15 | 15 | //! } |
16 | 16 | //! } |
17 | 17 | //! if (count_edges == 1) { |
18 | 18 | //! // nodes[0] <=> nodes[1] is a bridge |
19 | 19 | //! return; |
20 | 20 | //! } |
21 | | -//! for (int v : nodes) uf.join(v, nodes[0]); |
| 21 | +//! for (int u : nodes) uf.join(u, nodes[0]); |
22 | 22 | //! }); |
23 | 23 | //! vector<basic_string<int>> bridge_tree(n); |
24 | 24 | //! rep (i, 0, n) |
25 | | -//! for (int v : adj[i]) |
26 | | -//! if (!uf.sameSet(i, v)) |
27 | | -//! bridge_tree[uf.find(i)] += uf.find(v); |
| 25 | +//! for (int u : adj[i]) |
| 26 | +//! if (!uf.sameSet(i, u)) |
| 27 | +//! bridge_tree[uf.find(i)] += uf.find(u); |
28 | 28 | //! } |
29 | 29 | //! |
30 | 30 | //! vector<basic_string<int>> adj(n); |
31 | 31 | //! vector<basic_string<int>> block_vertex_tree(2 * n); |
32 | 32 | //! int bcc_id = n; |
33 | 33 | //! bcc_callback(adj, [&](const vi& nodes) { |
34 | | -//! for (int v : nodes) { |
35 | | -//! block_vertex_tree[v] += bcc_id; |
36 | | -//! block_vertex_tree[bcc_id] += v; |
| 34 | +//! for (int u : nodes) { |
| 35 | +//! block_vertex_tree[u] += bcc_id; |
| 36 | +//! block_vertex_tree[bcc_id] += u; |
37 | 37 | //! } |
38 | 38 | //! bcc_id++; |
39 | 39 | //! }); |
|
44 | 44 | void bcc_callback(const auto& adj, auto f) { |
45 | 45 | int n = sz(adj), q = 0, s = 0; |
46 | 46 | vi t(n), st(n); |
47 | | - auto dfs = [&](auto&& self, int v) -> int { |
48 | | - int l = t[v] = ++q; |
49 | | - for (int u : adj[v]) { |
| 47 | + auto dfs = [&](auto&& self, int u) -> int { |
| 48 | + int l = t[u] = ++q; |
| 49 | + for (int v : adj[u]) { |
50 | 50 | int siz = s, lu = 0; |
51 | | - l = min(l, t[u] ?: (lu = self(self, st[s++] = u))); |
52 | | - if (lu >= t[v]) { |
53 | | - st[s++] = v; |
| 51 | + l = min(l, t[v] ?: (lu = self(self, st[s++] = v))); |
| 52 | + if (lu >= t[u]) { |
| 53 | + st[s++] = u; |
54 | 54 | f({siz + all(st) - n + s}); |
55 | 55 | s = siz; |
56 | 56 | } |
|
0 commit comments