interface AdjList { int beg(); int nxt(); boolean end(); } class Edge { int v, w; double wt () { return 0.0; } Edge (int v, int w) { this.v = v; this.w = w; } } class GraphAdjList { private int Vcnt, Ecnt; private boolean digraph; private class Node { int v; Node next; Node (int x, Node t) { v = x; next = t; } } private Node adj[]; GraphAdjList (int V, boolean flag) { Vcnt = V; digraph = flag; } int V () { return Vcnt; } int E () { return Ecnt; } boolean directed () { return digraph; } Edge edge (int v, int w) { return new Edge (v, w); } void insert (Edge e) { int v = e.v, w = e.w; adj[v] = new Node (w, adj[v]); if (!digraph) adj[w] = new Node (v, adj[w]); Ecnt = Ecnt + 1; } private class AdjLinkedList implements AdjList { private int v; private Node t; AdjLinkedList (int v) { this.v = v; t = null; } public int beg() { t = adj[v]; return (t == null)? -1 : t.v; } public int nxt() { t = t.next; return (t == null)? -1 : t.v; } public boolean end () { return (t == null); } } AdjList getAdjList (int v) { return new AdjLinkedList(v); } static void randG(GraphAdjList G, int E) { int Vcnt = G.V(); double p = (E + E)/ Vcnt / (Vcnt-1); for (int i = 0; i < Vcnt; i++) { for (int j = i+1; j < Vcnt; j++) { if (Math.random() < p) G.insert(new Edge(i, j)); } } } }