@Override
    public AdjacencyMatrix subgraph(int[] vertices) {
        int[] v = vertices.clone();
        Arrays.sort(v);
        
        AdjacencyMatrix g = new AdjacencyMatrix(v.length, digraph);
        for (int i = 0; i < v.length; i++) {
            for (int j = 0; j < v.length; j++) {
                g.graph[i][j] = graph[v[i]][v[j]];
            }
        }
        
        return g;
    }
@Test
    public void testSubgraph() {
        System.out.println("subgraph digraph = false");

        AdjacencyMatrix graph = new AdjacencyMatrix(8, false);
        graph.addEdge(0, 2);
        graph.addEdge(1, 7);
        graph.addEdge(2, 6);
        graph.addEdge(7, 4);
        graph.addEdge(3, 4);
        graph.addEdge(3, 5);
        graph.addEdge(5, 4);

        int[] v = {1, 3, 7};
        AdjacencyMatrix sub = graph.subgraph(v);

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print(sub.getWeight(i, j) + " ");
            }
            System.out.println();
        }

        assertEquals(1.0, sub.getWeight(0, 2), 1E-10);
        assertEquals(1.0, sub.getWeight(2, 0), 1E-10);
    }