import edu.princeton.cs.algs4.*;

public class Graph {
    private static class Point {
        private double x, y;
        private Bag<Point> adj;

        public Point(double x, double y) {
            this.x = x;
            this.y = y;
           this.adj = new Bag<Point>();
        }

        public void addEdge(Point v) {
            adj.add(v);
        }

        public Iterable<Point> adj() {
            return adj;
        }

        public void drawItself() {
            StdDraw.filledCircle(x, y, 0.5);
        }

        public void drawTo(Point v) {
            StdDraw.line(x, y, v.x, v.y);
        }
    }

    final static private int XMAX = 100, YMAX = 100;
    private Point[] points;
    int V;

    public Graph(int V, int E) {
        this.V = V;
        points = new Point[V];

        for (int i = 0; i < V; i++)
            points[i] = new Point(StdRandom.uniform(0.0, XMAX), StdRandom.uniform(0.0, YMAX));

        for (int i = 0; i < E; i++) 
            points[StdRandom.uniform(V)].addEdge(points[StdRandom.uniform(V)]);
    }

    public void draw() {
        StdDraw.setXscale(0, XMAX);
        StdDraw.setYscale(0, YMAX);
        StdDraw.setPenColor(StdDraw.RED);
        StdDraw.setPenRadius(0.0005);

        for (int i = 0; i < V; i++) {
            points[i].drawItself();
            for (Point v: points[i].adj()) {
                v.drawItself();
                points[i].drawTo(v);
            }
        }
    }

    public static void main(String[] args) {
        int V = Integer.parseInt(args[0]);
        int E = Integer.parseInt(args[1]);
        Graph g = new Graph(V, E);
        g.draw();
    }
}

@@ -25,16 +25,35 @@
 algs4.*;
+%0Aimport java.awt.*;
 %0A%0Apublic
@@ -100,16 +100,43 @@
 Point %7B%0A
+        private int index;%0A
         
@@ -228,16 +228,27 @@
 double y
+, int index
 ) %7B%0A    
@@ -287,24 +287,56 @@
 this.y = y;%0A
+            this.index = index;%0A
            t
@@ -366,32 +366,98 @@
 %3E();%0A        %7D%0A%0A
+        public int index() %7B%0A            return index;%0A        %7D%0A%0A
         public v
@@ -619,19 +619,85 @@
 wItself(
-) %7B
+Color color, double radius) %7B%0A            StdDraw.setPenColor(color);
 %0A       
@@ -732,11 +732,14 @@
  y, 
-0.5
+radius
 );%0A 
@@ -774,35 +774,145 @@
 d drawTo(Point v
-) %7B
+, Color color, double radius) %7B%0A            StdDraw.setPenColor(color);%0A            StdDraw.setPenRadius(radius);
 %0A            Std
@@ -1261,16 +1261,19 @@
 0, YMAX)
+, i
 );%0A%0A    
@@ -1493,50 +1493,8 @@
 X);%0A
-        StdDraw.setPenColor(StdDraw.RED);%0A
     
@@ -1591,32 +1591,48 @@
 s%5Bi%5D.drawItself(
+StdDraw.RED, 0.5
 );%0A            f
@@ -1692,16 +1692,32 @@
 wItself(
+StdDraw.RED, 0.5
 );%0A     
@@ -1745,19 +1745,808 @@
 drawTo(v
-);%0A
+, StdDraw.RED, 0.0005);%0A            %7D%0A        %7D%0A    %7D%0A%0A    private boolean%5B%5D marked;%0A%0A    public void depthFirstSearch() %7B%0A        StdDraw.setPenRadius(0.005);%0A%0A        marked = new boolean%5BV%5D;%0A        for (int i = 0; i %3C V; i++)%0A            marked%5Bi%5D = false;%0A%0A        Color color = StdDraw.BLUE;%0A        for (int i = 0; i %3C V; i++) %7B%0A            dfs(points%5Bi%5D, color);%0A            color = color.darker().darker();%0A        %7D%0A    %7D%0A%0A    private void dfs(Point u, Color color) %7B%0A        if (!marked%5Bu.index()%5D) %7B%0A            marked%5Bu.index()%5D = true;%0A            u.drawItself(color, 0.7);%0A            for (Point v: u.adj())%0A                if (!marked%5Bv.index()%5D) %7B%0A                    u.drawTo(v, color, 0.003);%0A                    //StdDraw.show(300);%0A                    dfs(v, color);%0A    
         
@@ -2748,20 +2748,50 @@
   g.draw();%0A
+        g.depthFirstSearch();%0A
     %7D%0A%7D%0A

implement depth-first-search and its animation