You are given a directed graph as an adjacency list, where graph[i] lists the nodes reachable in one step from node i.
A node is terminal if it has no outgoing edges. A node is safe if every possible path starting from it leads to a terminal node - in other words, it can never get stuck in a cycle.
Return all safe nodes, sorted ascending.