src/graph/scc/tarjan/lib.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../../../util/alias/others/lib.hpp" | ||
| 4 | |||
| 5 | namespace tifa_libs { | ||
| 6 | |||
| 7 | struct tarjan { | ||
| 8 | u32 id; | ||
| 9 | vecu scc_id, dfn, low; | ||
| 10 | vvecu belongs; | ||
| 11 | |||
| 12 | 30 | CEXP void build(cT_(vvecu) g) NE { | |
| 13 | 30 | u32 cnt = 0, n = u32(g.size()); | |
| 14 | 30 | vecu s; | |
| 15 | 30 | vecb ins(n); | |
| 16 | 60 | id = 0, dfn = low = scc_id = vecu(n, n); | |
| 17 | 18715066 | auto dfs = [&](auto&& dfs, u32 u) NE -> void { | |
| 18 |
2/2✓ Branch 11 taken 17871094 times.
✓ Branch 12 taken 18715066 times.
|
36586160 | for (dfn[u] = low[u] = cnt++, s.push_back(u), ins[u] = true; auto v : g[u]) |
| 19 |
2/2✓ Branch 1 taken 10709410 times.
✓ Branch 2 taken 7161684 times.
|
17871094 | if (dfn[v] == n) dfs(dfs, v), low[u] = min(low[u], low[v]); |
| 20 |
2/2✓ Branch 2 taken 986124 times.
✓ Branch 3 taken 6175560 times.
|
7161684 | else if (ins[v]) low[u] = min(low[u], dfn[v]); |
| 21 |
2/2✓ Branch 2 taken 16164502 times.
✓ Branch 3 taken 2550564 times.
|
18715066 | if (low[u] == dfn[u]) { |
| 22 | 16164502 | belongs.emplace_back(); | |
| 23 | do { | ||
| 24 | 18715066 | cu32 v = s.back(); | |
| 25 | 18715066 | s.pop_back(); | |
| 26 | 18715066 | ins[v] = false, belongs[scc_id[v] = id].push_back(v); | |
| 27 |
2/2✓ Branch 0 taken 16164502 times.
✓ Branch 1 taken 2550564 times.
|
18715066 | if (v == u) return void(++id); |
| 28 | 2550564 | } while (true); | |
| 29 | } | ||
| 30 | 30 | }; | |
| 31 |
2/2✓ Branch 0 taken 18715066 times.
✓ Branch 1 taken 30 times.
|
18715096 | flt_ (u32, i, 0, n) |
| 32 |
2/2✓ Branch 1 taken 8005656 times.
✓ Branch 2 taken 10709410 times.
|
18715066 | if (dfn[i] == n) dfs(dfs, i); |
| 33 | 30 | } | |
| 34 | }; | ||
| 35 | |||
| 36 | } // namespace tifa_libs | ||
| 37 |