执行贪婪着色的 C++ 程序
这是一个执行贪婪着色的C++程序
算法:
Begin Take the number of vertices and edges as input. Create function greedyColoring() to assign color to vertices: A) Assign the first color to first vertex. B) Initialize the remaining vertices. C) Declare a temporary array to store the available colors. D) Assign color to the remaining vertices. Print the solution. End
示例代码
#include#include using namespace std; int n,e,i,j; vector > g; vector col; bool visit[1001]; void greedyColoring() { col[0] = 0; for (i=1;i >n>>e; cout<<"\n"; g.resize(n); col.resize(n); memset(visit,0,sizeof(visit)); for(i=0;i >a>>b; a--; b--; g[a].push_back(b); g[b].push_back(a); } greedyColoring(); for(i=0;i 输出结果 分别输入顶点数和边数:7 6 Enter edge vertices of edge 1 :4 5 Enter edge vertices of edge 2 :2 3 Enter edge vertices of edge 3 :1 1 Enter edge vertices of edge 4 :1 4 Enter edge vertices of edge 5 :6 7 Enter edge vertices of edge 6 :2 2 Vertex 1 is coloured with 1 Vertex 2 is coloured with 1 Vertex 3 is coloured with 2 Vertex 4 is coloured with 2 Vertex 5 is coloured with 1 Vertex 6 is coloured with 1 Vertex 7 is coloured with 2
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下