#include <iostream>
#include <vector>
#include <queue>
#include <unordered_set>
using namespace std;
class Graph {
public:
int V;
vector<vector<int>> adj;
Graph(int V) {
this->V = V;
adj.resize(V);
}
void addEdge(int u, int v) {
adj[u].push_back(v);
adj[v].push_back(u);
}
};
// 贪心算法着色函数
int greedyColoring(Graph& graph) {
// 存储每个节点的颜色
vector<int> colors(graph.V, -1);
// 从第一个节点开始遍历
for (int u = 0; u < graph.V; u++) {
// 存储相邻节点已经被使用的颜色
unordered_set<int> usedColors;
// 遍历相邻节点
for (int v : graph.adj[u]) {
if (colors[v] != -1) {
// 如果相邻节点已经被着色,则将其颜色加入已使用颜色集合
usedColors.insert(colors[v]);
}
}
// 寻找可用的最小颜色
int color = 0;
while (usedColors.find(color) != usedColors.end()) {
color++;
}
// 为当前节点着色
colors[u] = color;
}
// 返回所需的最小颜色数
return *max_element(colors.begin(), colors.end()) + 1;
}
int main() {
Graph graph(6);
graph.addEdge(0, 1);
graph.addEdge(0, 2);
graph.addEdge(1, 3);
graph.addEdge(2, 4);
graph.addEdge(3, 5);
graph.addEdge(4, 5);
int minColors = greedyColoring(graph);
cout << "Minimum number of colors required: " << minColors << endl;
return 0;
}