[algorithm] Best algorithm for detecting cycles in a directed graph