标签:
//稠密图,邻接矩阵表示 struct edge{ int v, w, val; edge(int v = -1, int w = -1, int val = NOEDGE) :v(v), w(w), val(val){} }; struct denseGraph{ int Vcnt, Ecnt; //顶点数,边数 bool dg; //有向图 ? vector< vector<int> > adj; //邻接矩阵 denseGraph(int v, bool dg = false) :adj(v), Vcnt(v), Ecnt(0), dg(dg){ for (int i = 0; i < v; ++i) adj[i].assign(v, NOEDGE); } void insert(edge e){ int v = e.v, w = e.w, val = e.val; if (adj[v][w] == NOEDGE) ++Ecnt; adj[v][w] = val; if (!dg) adj[w][v] = val; } void show(){ printf("Vcnt = %d, Ecnt = %d, Directed : ", Vcnt, Ecnt); if (dg) printf("true\n"); else printf("false\n"); for (int i = 0; i < Vcnt; ++i){ for (int j = 0; j < Vcnt-1; ++j) cout << adj[i][j] << ‘ ‘; cout << adj[i][Vcnt - 1] << endl; } } };
标签:
原文地址:http://www.cnblogs.com/jokoz/p/4762572.html