MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / find_cycle

Function find_cycle

code/other/floyds_algorithm.cpp:1–8  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1ii find_cycle(int x0, int (*f)(int)) {
2 int t = f(x0), h = f(t), mu = 0, lam = 1;
3 while (t != h) t = f(t), h = f(f(h));
4 h = x0;
5 while (t != h) t = f(t), h = f(h), mu++;
6 h = f(t);
7 while (t != h) h = f(h), lam++;
8 return ii(mu, lam); }
9// vim: cc=60 ts=2 sts=2 sw=2:

Callers 1

testFunction · 0.85

Calls 1

fFunction · 0.85

Tested by 1

testFunction · 0.68