reorder the adjacency matrix