Vertex Coloring
(The discussion concerns simple undirected graphs without self-loops.)
Color the vertices of an undirected graph so that adjacent vertices have different colors. If G is -colorable but not -colorable, then k is the chromatic number of G, denoted by .
For every graph G, , where is the maximum degree.
Brooks's Theorem
Suppose the connected graph is neither complete nor an odd cycle. Then .
Proof
Proof
Let , and use mathematical induction.
For , the claim is obvious.
Now assume that the claim holds for ; we will strengthen the claim step by step.
We may restrict attention to -regular graphs, because a nonregular graph can be viewed as a regular graph with some edges deleted, and this process does not affect the conclusion.
For any regular graph G that is neither complete nor an odd cycle, choose a vertex v and consider the subgraph . By the induction hypothesis, ; it remains only to prove that inserting v into H does not affect the conclusion.
Let . Suppose H is colored with colors , and let the neighbors of v be . We may assume that these neighbors of v have pairwise distinct colors; otherwise the claim is proved.
Now let the vertices of H colored or , together with all edges between them, form the subgraph . We may assume that any two distinct vertices and lie in the same connected component of ; otherwise, if they lay in different components, we could swap the colors of every vertex in one component, making and have the same color.
Here, swapping colors means that if a graph uses only two colors a and b, every vertex originally colored a is recolored b, and every vertex originally colored b is recolored a.
Let the component above be . Then can only be a path from to . Since has degree in H, the colors of the neighbors of in H must all be distinct; otherwise we could give another color, causing a duplicate with the colors of v's other neighbors. Therefore, has exactly one neighbor in , and is analogous. We then take a path in from to and call it P. If , we can recolor the vertices along P in order. Let u be the first vertex encountered whose degree is greater than 2. Its neighbors use at most colors, so u can be recolored, making and disconnected.
It is then easy to see that for any three distinct vertices , , and , .
The strengthening of the claim is now complete.
The rest is simple. If the neighbors of v are pairwise adjacent, the claim is proved. Otherwise, suppose and are not adjacent. In , take the neighbor of w and swap the colors in . In the resulting graph, , a contradiction.
This proves the claim.
Welsh–Powell Algorithm
The Welsh–Powell algorithm is a greedy algorithm for finding a coloring when the maximum number of colors is not restricted.
For a simple undirected graph G without self-loops, let satisfy.
The Welsh–Powell algorithm uses at most colors, and its time complexity is .
Procedure
- Sort the currently uncolored vertices in descending order of degree.
- Color the first vertex with an unused color.
- Traverse the remaining vertices in order. If the current vertex is not adjacent to any vertex with the same color as the first vertex, color it with that same color.
- If uncolored vertices remain, return to step 1; otherwise, finish.
An example follows:

(Generated by Graph Editor.)
First sort the vertices in descending order of degree:
| Order | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Vertex number | 4 | 5 | 0 | 2 | 9 | 1 | 3 | 6 | 10 | 12 | 7 | 8 | 11 |
| Degree | 5 | 5 | 4 | 4 | 4 | 3 | 3 | 3 | 3 | 3 | 2 | 2 | 1 |
| 1 | 2 | 3 | 4 | 5 | 4 | 4 | 4 | 4 | 4 | 3 | 3 | 2 |
Thus the Welsh–Powell algorithm uses at most 5 colors.
Moreover, because this graph contains the subgraph , its chromatic number is at least 3.
-
First coloring:

Colored 1 Color vertices
4 9 3 11. -
Second coloring:

Colored 2 Color vertices
5 2 6 7 8. -
Third coloring:

Colored 3 Color vertices
0 1 10 12.
Proof
Proof
For a simple undirected graph G without self-loops, let satisfy
Set . From , choose a subset whose elements satisfy
-
, where .
-
If
then if and only if both
- ;
- is not adjacent to any of .
Clearly, coloring the vertices in with color i gives exactly the coloring produced by the Welsh–Powell algorithm. Clearly,
- ;
- ;
- .
We only need to prove
where
.
The inequality on the left is obvious; consider the right-hand inequality.
First, we readily obtain the following:
If , then v is adjacent to at least one vertex in each of , and therefore .
Consequently,
.
On the other hand, from the construction of the sequence , we readily see that
.
Combining the two relations proves the result.
Edge Coloring
For an undirected graph, edge coloring requires adjacent edges to receive different colors. If G is k-edge-colorable but not -edge-colorable, k is called the edge-chromatic number of G, denoted by .
Vizing's Theorem
If G is a simple graph, then .
If G is bipartite, then .
When is odd (), ; when is even, .
Constructive Proof of Vizing's Theorem for Bipartite Graphs
Proof
Add edges to the bipartite graph in order.
When trying to add the edge , look for the smallest-numbered unused color at and , and suppose these colors are and , respectively.
If , we can directly assign to this edge.
Otherwise, suppose . We can try to change the color of the edge incident to vertex whose color is to .
This process can be viewed approximately as a finite unique augmenting path starting at and successively traversing edges with colors .
Since the augmenting path is finite, we can swap the colors of all its edges: edges originally colored are changed to , and edges originally colored are changed to .
By the bipartite-graph property, vertex cannot be a vertex on the augmenting path; otherwise the smallest unused color would be , a contradiction.
Thus, after the augmentation, we can assign the color of the edge connecting and to .
The total construction time complexity is .
Example Code: UVa10615 Rooks
#include <iostream>
constexpr int MAXN = 100;
int t;
int n;
char a[MAXN + 10][MAXN + 10];
int c[MAXN + 10][MAXN + 10];
int ans;
namespace graph {
struct Vertex {
int head;
int deg;
int vis[MAXN + 10];
} vertex[2 * MAXN + 10], e;
struct Edge {
int head;
int next;
int col;
} edge[2 * MAXN * MAXN + 10];
int ecnt;
void init() {
for (int i = 0; i < MAXN + 10; i++) std::fill(c[i], c[i] + MAXN + 10, 0);
for (int i = 1; i <= 2 * MAXN; i++) vertex[i] = e;
for (int i = 0; i <= 2 * MAXN * MAXN; i++) edge[i].col = 0;
ecnt = 1;
ans = 0;
return;
}
void addEdge(int tail, int head) {
ecnt++;
edge[ecnt].head = head;
edge[ecnt].next = vertex[tail].head;
vertex[tail].head = ecnt;
vertex[tail].deg++;
return;
}
int get(int u) {
for (int i = 1; i <= n; i++)
if (!vertex[u].vis[i]) return i;
exit(1);
}
void DFS(int u, int ori, int upd) {
if (vertex[u].vis[ori] == 0) {
vertex[u].vis[upd] = 0;
return;
}
int e = vertex[u].vis[ori];
int v = edge[e].head;
DFS(v, upd, ori);
edge[e].col = upd;
edge[e ^ 1].col = upd;
vertex[u].vis[upd] = e;
vertex[v].vis[upd] = e ^ 1;
return;
}
void AddEdge(int u, int v) {
addEdge(u, v);
addEdge(v, u);
return;
}
void solve() {
for (int u = 1; u <= n; u++) {
for (int e = vertex[u].head; e; e = edge[e].next) {
int v = edge[e].head;
if (edge[e].col) continue;
int lu = get(u);
int lv = get(v);
if (lu < lv) DFS(v, lu, lv);
if (lu > lv) DFS(u, lv, lu);
int l = std::min(lu, lv);
vertex[u].vis[l] = e;
vertex[v].vis[l] = e ^ 1;
edge[e].col = l;
edge[e ^ 1].col = l;
}
}
}
void generate() {
for (int u = 1; u <= n; u++) {
for (int e = vertex[u].head; e; e = edge[e].next) {
int v = edge[e].head;
c[u][v - n] = edge[e].col;
}
}
return;
}
} // namespace graph
void mian() {
graph::init();
std::cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) std::cin >> a[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (a[i][j] == '*') graph::AddEdge(i, j + n);
for (int i = 1; i <= n * 2; i++) ans = std::max(ans, graph::vertex[i].deg);
graph::solve();
graph::generate();
std::cout << ans << '\n';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) std::cout << c[i][j] << ' ';
std::cout << '\n';
}
return;
}
int main() {
std::cin >> t;
while (t--) mian();
return 0;
}
A Challenging Example: UOJ 444 Bipartite Graph
The author created this problem as an assignment for the first round of the training team in 2018.
First, we can observe that the lower bound on the answer is the number of vertices whose degree is not a multiple of k.
The lower-bound construction splits vertices in the bipartite graph.
If , split the vertex into vertices of degree k and one vertex of degree .
If , split it into vertices of degree k.
The split vertices have the same meaning as the original vertex, so under the degree constraint, an edge endpoint may be connected to any one of the split vertices.
By Vizing's theorem, we can clearly construct a k-coloring of the resulting graph.
The edge-deletion part is not closely related to Vizing's theorem, so it is omitted here.
Interested readers may read the solution written by the author at the time.
The Chromatic Polynomial
denotes the total number of distinct k-colorings of G.
For a simple undirected graph G,
- If , then .
- If , then .
Theorem: Let be a vertex cut set of G, let be a complete subgraph of G with vertices, and suppose has connected components. Then
where .
References
- Graph coloring - Wikipedia
- Welsh, D. J. A.; Powell, M. B. (1967), "An upper bound for the chromatic number of a graph and its application to timetabling problems", The Computer Journal, 10 (1): 85–86