From 1385bf25d24df9d8d6618832f549cdeb786e16f5 Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Wed, 27 Nov 2024 19:29:50 -0600 Subject: [PATCH] fix --- library/graphs/functional_graph_processor.hpp | 12 ++++++------ .../handmade_tests/functional_graph.test.cpp | 17 +++++++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/library/graphs/functional_graph_processor.hpp b/library/graphs/functional_graph_processor.hpp index 71792d3e..1cf187b9 100644 --- a/library/graphs/functional_graph_processor.hpp +++ b/library/graphs/functional_graph_processor.hpp @@ -3,7 +3,8 @@ //! @code //! // 0 <= a[i] < n //! auto [t2, cycle] = func_graph(a); -//! int root = cycle[t2[v].i][t2[v].j]; +//! auto [cyc_id, cyc_pos] = t2[v].root_of; +//! int root = cycle[cyc_id][cyc_pos]; //! bool is_on_cycle = (v == root); //! @endcode //! root = first reachable node on cycle @@ -12,7 +13,7 @@ //! @space O(n) struct func_graph { struct node { - int i, j; + pii root_of; vi childs; }; vector t; @@ -29,8 +30,8 @@ struct func_graph { if (state[u] == 1) { cycle.emplace_back(); while (state[u] == 1) { - t[u].i = sz(cycle) - 1; - t[u].j = sz(cycle.back()); + t[u].root_of = { + sz(cycle) - 1, sz(cycle.back())}; cycle.back().push_back(u); state[u] = 2; u = a[u]; @@ -38,8 +39,7 @@ struct func_graph { } int v = i; while (state[v] == 1) { - t[v].i = t[u].i; - t[v].j = t[u].j; + t[v].root_of = t[u].root_of; t[a[v]].childs.push_back(v); state[v] = 2; v = a[v]; diff --git a/tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp b/tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp index 99486432..2eb214a2 100644 --- a/tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp +++ b/tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp @@ -129,17 +129,22 @@ int main() { functional_graph_processor fgp(a); assert(cycle == fgp.cycle); for (int i = 0; i < n; i++) { - int root = cycle[t[i].i][t[i].j]; + int root = + cycle[t[i].root_of.first][t[i].root_of.second]; assert(t[i].childs == fgp.abr[i]); assert((root == i) == (fgp.cycle_id[i] != -1)); if (root == i) { - assert(t[i].i == fgp.cycle_id[i]); - assert(t[i].j == fgp.cycle_pos[i]); - int cyc_len = ssize(cycle[t[i].i]); + assert(t[i].root_of.first == fgp.cycle_id[i]); + assert(t[i].root_of.second == fgp.cycle_pos[i]); + int cyc_len = ssize(cycle[t[i].root_of.first]); assert( - cycle[t[i].i][(t[i].j + 1) % cyc_len] == a[i]); + cycle[t[i].root_of.first] + [(t[i].root_of.second + 1) % cyc_len] == + a[i]); assert(fgp.cycle_prev[i] == - cycle[t[i].i][(t[i].j - 1 + cyc_len) % cyc_len]); + cycle[t[i].root_of.first] + [(t[i].root_of.second - 1 + cyc_len) % + cyc_len]); } else { assert(fgp.cycle_prev[i] == -1); }