if (!hasContiguousVertices(g))
throw new IllegalArgumentException(
"Vertices must be in continugous order");
double[] centralities = new double[g.order()];
IntIterator vertexIter = g.vertices().iterator();
while (vertexIter.hasNext()) {
int s = vertexIter.nextInt();
Deque<Integer> S = new ArrayDeque<Integer>();
// Initialize P to an empty list for each vertex
List<List<Integer>> P = new ArrayList<List<Integer>>(g.order());
for (int i = 0; i < g.order(); ++i)
P.add(new ArrayList<Integer>());
double[] sigma = new double[g.order()];
sigma[s] = 1;
double[] d = new double[g.order()];
Arrays.fill(d, -1);
d[s] = 0;
Queue<Integer> Q = new ArrayDeque<Integer>();
Q.add(s);
while (!Q.isEmpty()) {
int v = Q.poll();
S.offer(v);
IntIterator neighborIter = g.getNeighbors(v).iterator();
while (neighborIter.hasNext()) {
int w = neighborIter.nextInt();
// Check whether this is the first time we've seen vertex w
if (d[w] < 0) {
Q.offer(w);
d[w] = d[v] + 1;
}