File tree Expand file tree Collapse file tree 1 file changed +19
-21
lines changed
Expand file tree Collapse file tree 1 file changed +19
-21
lines changed Original file line number Diff line number Diff line change @@ -16,29 +16,27 @@ struct func_graph {
1616 vector<basic_string<int >> cycle, childs;
1717 func_graph (const vi& a): root_of(sz(a)), childs(sz(a)) {
1818 vi state (sz (a));
19- rep (i, 0 , sz (a)) {
20- if (state[i] == 0 ) {
21- int u = i;
22- while (state[u] == 0 ) {
23- state[u] = 1 ;
19+ rep (i, 0 , sz (a)) if (state[i] == 0 ) {
20+ int u = i;
21+ while (state[u] == 0 ) {
22+ state[u] = 1 ;
23+ u = a[u];
24+ }
25+ if (state[u] == 1 ) {
26+ cycle.emplace_back ();
27+ while (state[u] == 1 ) {
28+ root_of[u] = {sz (cycle) - 1 , sz (cycle.back ())};
29+ cycle.back () += u;
30+ state[u] = 2 ;
2431 u = a[u];
2532 }
26- if (state[u] == 1 ) {
27- cycle.emplace_back ();
28- while (state[u] == 1 ) {
29- root_of[u] = {sz (cycle) - 1 , sz (cycle.back ())};
30- cycle.back () += u;
31- state[u] = 2 ;
32- u = a[u];
33- }
34- }
35- int v = i;
36- while (state[v] == 1 ) {
37- root_of[v] = root_of[u];
38- childs[a[v]] += v;
39- state[v] = 2 ;
40- v = a[v];
41- }
33+ }
34+ int v = i;
35+ while (state[v] == 1 ) {
36+ root_of[v] = root_of[u];
37+ childs[a[v]] += v;
38+ state[v] = 2 ;
39+ v = a[v];
4240 }
4341 }
4442 }
You can’t perform that action at this time.
0 commit comments