package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/find-eventual-safe-states/
 */
public class Problem802 {
    public List<Integer> eventualSafeNodes(int[][] graph) {
        // TODO
        return new ArrayList<>();
    }

    public static void main(String[] args) {
        Problem802 prob = new Problem802();
        System.out.println(prob.eventualSafeNodes(new int[][]{
            {1, 2}, {2, 3}, {5}, {0}, {5}, {}, {}
        })); // [2,4,5,6]
        System.out.println(prob.eventualSafeNodes(new int[][]{
            {1,2},{1},{0}
        })); // []
    }
}

@@ -230,48 +230,1003 @@
     
-// TODO%0A        return new ArrayList%3C%3E()
+List%3CInteger%3E result = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C graph.length; i++) %7B%0A            boolean%5B%5D visited = new boolean%5B10000%5D;%0A            boolean%5B%5D onStack = new boolean%5B10000%5D;%0A            Cycle cycle = new Cycle();%0A            dfs(graph, i, visited, onStack, cycle);%0A            if (!cycle.cycle) %7B%0A                result.add(i);%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    private static class Cycle %7B%0A        private boolean cycle;%0A    %7D%0A%0A    private static void dfs(int%5B%5D%5B%5D graph, int source, boolean%5B%5D visited,%0A                            boolean%5B%5D onStack, Cycle cycle) %7B%0A        visited%5Bsource%5D = true;%0A        onStack%5Bsource%5D = true;%0A        for (int neighbor : graph%5Bsource%5D) %7B%0A            if (!visited%5Bneighbor%5D) %7B%0A                dfs(graph, neighbor, visited, onStack, cycle);%0A            %7D else %7B%0A                if (onStack%5Bneighbor%5D) %7B%0A                    cycle.cycle = true;%0A                %7D%0A            %7D%0A        %7D%0A        onStack%5Bsource%5D = false
 ;%0A  
@@ -1265,16 +1265,17 @@
 (String%5B
+ 
 %5D args) 
@@ -1541,15 +1541,18 @@
  %7B1,
+ 
 2%7D,
+ 
 %7B1%7D,
+ 
 %7B0%7D%0A

Update problem 802