Skip to content

Commit b0d2ea7

Browse files
committed
changed another place
1 parent e9e1681 commit b0d2ea7

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

library/graphs/functional_graph_processor.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
struct func_graph {
1515
struct node {
1616
pii root_of;
17-
vi childs;
17+
basic_string<int> childs;
1818
};
1919
vector<node> t;
2020
vector<vi> cycle;
@@ -40,7 +40,7 @@ struct func_graph {
4040
int v = i;
4141
while (state[v] == 1) {
4242
t[v].root_of = t[u].root_of;
43-
t[a[v]].childs.push_back(v);
43+
t[a[v]].childs += v;
4444
state[v] = 2;
4545
v = a[v];
4646
}

tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#define PROBLEM \
2-
"https://onlinejudge.u-aizu.ac.jp/problems/ITP1_1_A"
1+
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/ITP1_1_A"
32
#include "../template.hpp"
43
#include "../../../library/contest/random.hpp"
54
#include "../../../library/graphs/functional_graph_processor.hpp"
@@ -9,7 +8,7 @@ struct functional_graph_processor {
98
init(sz(next));
109
build(next);
1110
}
12-
template<class Graph_t>
11+
template <class Graph_t>
1312
functional_graph_processor(const Graph_t &g) {
1413
init(g.n);
1514
build(g);
@@ -101,24 +100,31 @@ struct functional_graph_processor {
101100
}
102101
int n;
103102
vector<vector<int>> cycle;
104-
vector<int> cycle_id; // id of the cycle it belongs to,
105-
// -1 if not part of one
106-
vector<int> cycle_pos; // position in its cycle, -1 if
107-
// not part of one
108-
vector<int> cycle_prev; // previous vertex in its cycle,
109-
// -1 if not part of one
110-
vector<int> component_size; // size of its weakly
111-
// connected component
112-
vector<int> root_of; // first reachable node in a cycle
113-
vector<int> depth; // distance to its root
114-
vector<vector<int>>
115-
abr; // forest of arborescences of reversed edges not
116-
// on the cycles
117-
vector<int> order; // dfs order of abr
118-
vector<int> pos; // pos in the dfs order
119-
vector<int> end; // [pos[u], end[u]) denotes the subtree
120-
vector<int> size; // size of the subtree in abr
103+
vector<int> cycle_id; // id of the cycle it belongs to,
104+
// -1 if not part of one
105+
vector<int> cycle_pos; // position in its cycle, -1 if
106+
// not part of one
107+
vector<int> cycle_prev; // previous vertex in its cycle,
108+
// -1 if not part of one
109+
vector<int> component_size; // size of its weakly
110+
// connected component
111+
vector<int> root_of; // first reachable node in a cycle
112+
vector<int> depth; // distance to its root
113+
vector<vector<int>> abr; // forest of arborescences of reversed edges not
114+
// on the cycles
115+
vector<int> order; // dfs order of abr
116+
vector<int> pos; // pos in the dfs order
117+
vector<int> end; // [pos[u], end[u]) denotes the subtree
118+
vector<int> size; // size of the subtree in abr
121119
};
120+
121+
bool equal(const basic_string<int> &a, const vi &b) {
122+
if (sz(a) != sz(b)) return 0;
123+
for (int i = 0; i < sz(a); i++)
124+
if (a[i] != b[i]) return 0;
125+
return 1;
126+
}
127+
122128
int main() {
123129
cin.tie(0)->sync_with_stdio(0);
124130
for (int num_tests = 100; num_tests--;) {
@@ -129,23 +135,19 @@ int main() {
129135
functional_graph_processor fgp(a);
130136
assert(cycle == fgp.cycle);
131137
for (int i = 0; i < n; i++) {
132-
int root =
133-
cycle[t[i].root_of.first][t[i].root_of.second];
138+
int root = cycle[t[i].root_of.first][t[i].root_of.second];
134139
assert(root == fgp.root_of[i]);
135-
assert(t[i].childs == fgp.abr[i]);
140+
assert(equal(t[i].childs, fgp.abr[i]));
136141
assert((root == i) == (fgp.cycle_id[i] != -1));
137142
if (root == i) {
138143
assert(t[i].root_of.first == fgp.cycle_id[i]);
139144
assert(t[i].root_of.second == fgp.cycle_pos[i]);
140145
int cyc_len = ssize(cycle[t[i].root_of.first]);
141-
assert(
142-
cycle[t[i].root_of.first]
143-
[(t[i].root_of.second + 1) % cyc_len] ==
144-
a[i]);
146+
assert(cycle[t[i].root_of.first][(t[i].root_of.second + 1) % cyc_len] ==
147+
a[i]);
145148
assert(fgp.cycle_prev[i] ==
146-
cycle[t[i].root_of.first]
147-
[(t[i].root_of.second - 1 + cyc_len) %
148-
cyc_len]);
149+
cycle[t[i].root_of.first]
150+
[(t[i].root_of.second - 1 + cyc_len) % cyc_len]);
149151
} else {
150152
assert(fgp.cycle_prev[i] == -1);
151153
}

0 commit comments

Comments
 (0)