Write a function to detect a cycle in a linked list or perform a specific tree traversal.
Implement the linked-list cycle option. The list is represented by nodes, where nodes[i] is the index of the next node, or -1 for the end, and head is the starting index. Return True if traversal from head eventually revisits a node, otherwise return False. Use O(1) auxiliary space and do not modify the input.
def has_cycle(nodes, head):