Pythonにおける隣接リストを用いたグラフの表現方法
class Graph: def __init__(self, num_vertices): self.num_vertices = num_vertices self.adj_list = [[] for _ in range(num_vertices)] def add_edge(self, source, destination): self.adj_list[source].append(destination) self.adj_list[destination].append(source) >>More