@@ -0,0 +1,1928 @@
+package me.alivecode.algs4;%0A%0Aimport edu.princeton.cs.algs4.In;%0Aimport edu.princeton.cs.algs4.StdOut;%0A%0A/**%0A * Created by oujt on 17-2-21.%0A */%0Apublic class KosarajuSharirSCC %7B%0A    private boolean%5B%5D marked;%0A    private int count;%0A    private int%5B%5D id;%0A%0A    public KosarajuSharirSCC(Digraph DG) %7B%0A        DepthFirstOrder dfo = new DepthFirstOrder(DG.reverse());%0A%0A        marked = new boolean%5BDG.V()%5D;%0A        id = new int%5BDG.V()%5D;%0A        for(int v: dfo.reversePostOrder()) %7B%0A            if (!marked%5Bv%5D) %7B%0A                dfs(DG, v);%0A                count++;%0A            %7D%0A        %7D%0A    %7D%0A%0A    private void dfs(Digraph DG, int v) %7B%0A        marked%5Bv%5D = true;%0A        id%5Bv%5D = count;%0A%0A        for (int w : DG.adj(v)) %7B%0A            if (!marked%5Bw%5D) %7B%0A                dfs(DG, w);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public int count() %7B%0A        return count;%0A    %7D%0A%0A    public int id(int v) %7B%0A        validateVertex(v);%0A        return id%5Bv%5D;%0A    %7D%0A%0A    public boolean stronglyConnected(int v, int w) %7B%0A        validateVertex(v);%0A        validateVertex(w);%0A        return id%5Bv%5D == id%5Bw%5D;%0A    %7D%0A%0A    private void validateVertex(int v) %7B%0A        if (v %3C 0 %7C%7C v %3E= marked.length) throw new IllegalArgumentException();%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        In in = new In(args%5B0%5D);%0A        Digraph DG = new Digraph(in);%0A        KosarajuSharirSCC scc = new KosarajuSharirSCC(DG);%0A%0A        Queue%3CInteger%3E%5B%5D components = (Queue%3CInteger%3E%5B%5D) new Queue%5Bscc.count()%5D;%0A        for(int i = 0; i %3C scc.count(); i++) %7B%0A            components%5Bi%5D = new Queue%3C%3E();%0A        %7D%0A        for(int v = 0; v %3C DG.V(); v++) %7B%0A            components%5Bscc.id(v)%5D.enqueue(v);%0A        %7D%0A%0A        StdOut.println(scc.count() + %22 strongly connected components:%22);%0A        for(int i = 0; i %3C scc.count(); i++) %7B%0A            for(int v : components%5Bi%5D) %7B%0A                StdOut.print(v + %22 %22);%0A            %7D%0A            StdOut.println();%0A        %7D%0A    %7D%0A%7D%0A

Add KosarajuSharirSCC class,implement of Kosaraju-Sharir for determining strongly connected components.