def distances(g: Graph): dist = shortest_distance(g, directed=g.is_directed()) return np.array([[y for y in x] for x in dist], dtype=int)
def components(g: Graph): comp, *_ = label_components(g, directed=g.is_directed()) com = np.zeros(np.max(comp.a) + 1, dtype=int) np.add.at(com, comp.a, 1) return com