[ create a new paste ] login | about

Link: http://codepad.org/KIRsKxAe    [ raw code | output | fork ]

Python, pasted on Nov 27:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from collections import defaultdict

a = [5, 4, 0, 3, 1, 2, 6]
d = defaultdict(set)
for i in range(len(a)):
    s = set()
    idx = i
    while idx not in s:
        s.add(idx)
        idx = a[idx]
    d[len(s)].add(tuple(s))
res = max(d)
path = d[max(d)]
print(res, path)


Output:
1
(3, set([(0, 2, 5)]))


Create a new paste based on this one


Comments: