Skip to content

Instantly share code, notes, and snippets.

@yaboong
Created February 18, 2018 18:10
Show Gist options
  • Save yaboong/91d9e3fd48f24d7d1716aeb3713fe1f9 to your computer and use it in GitHub Desktop.
Save yaboong/91d9e3fd48f24d7d1716aeb3713fe1f9 to your computer and use it in GitHub Desktop.
import java.util.LinkedList;
/**
* Created by yaboong on 2018. 2. 19..
*/
public class Graph {
private final int V;
private LinkedList<Integer>[] adj;
public Graph(int V) {
this.V = V;
adj = new LinkedList[V];
for (int v = 0; v < V; v++)
adj[v] = new LinkedList<>();
}
public void addEdge(int v, int w) {
adj[v].add(w);
adj[w].add(v);
}
public Iterable<Integer> adj(int v) { return adj[v]; }
public int V() { return V; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment