States that always halt
A program is a state machine with states 0 to n - 1, where n = len(moves). moves[i] lists the states it can jump to from state i; the list may repeat a state or include i itself. A state with no moves halts. A state is safe if the program is sure to halt from it whichever moves it takes: no sequence of moves from it goes on forever. Return every safe state in increasing order.
Besides the tests, one large input (2,600 states, 5,200 moves) with a ~150 ms limit (scaled to your device's speed): brute force won't pass.
Examples
safe_states([[1],[2],[0,3],[],[3],[4,1]])→[3,4]safe_states([[],[0],[1,1]])→[0,1,2]safe_states([[0]])→[]