グラフは離散構造を記述するための基本的な道具である.特に辺に重みのある有向グラフはもっともよく使われる構造の一つである.
グラフの表現には大きく分けて隣接辺リスト,隣接行列の二つがある.隣接辺リストは各頂点にそれを始点とする辺の情報をリストとして格納する.隣接行列は正方行列で (i,j) 成分に辺 (i,j) の情報を格納する.それぞれのメリット,デメリットは以下のとおり.
typedef int Weight; struct Edge { int src, dst; Weight weight; Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { } }; bool operator < (const Edge &e, const Edge &f) { return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!! e.src != f.src ? e.src < f.src : e.dst < f.dst; } typedef vector<Edge> Edges; typedef vector<Edges> Graph; typedef vector<Weight> Array; typedef vector<Array> Matrix;
Last Modified: 2007.11.10 20:42:50.