Finding loops in a linked list.
Represent the linked list with next_indices, where next_indices[i] gives the index of node i and -1 means the list ends. The head parameter gives the starting index, or -1 for an empty list. Return True if any node is reachable more than once by following next pointers; otherwise return False.
Implement has_cycle(next_indices, head).
def has_cycle(next_indices, head):