public static int degree(Graph G, int v) { int degree = 0; for (int w : G.adj(v)) degree++; return degree; }
public static int numberOfSelfLoops(Graph G) { int count = 0; for (int v = 0; v < G.V(); v++) for (int w : G.adj(v)) if (v == w) count++; return count / 2; }