How this calculation works
Minimize edge colors so each vertex pair has at least one path with all edge colors distinct.
rc(G)=min{|colors| : every u,v have a rainbow path}.A worked example
The default four-cycle has rainbow connection number 2; one coloring uses color 0 on three consecutive edges and color 1 on the fourth.
Good to know
Connected simple graph with 1–7 vertices and at most 10 edges. Exact canonical color assignments, all-pairs rainbow-path checks and a 2000000-state search cap. Ordinary rainbow connection only; cap exhaustion is unresolved.
Reference: Chartrand, Johns, McKeon and Zhang: Rainbow connection in graphs (opens in a new tab) ↗
A colorful route rather than proper coloring
A path is rainbow when none of its edge colors repeats. A graph is rainbow connected if every pair of vertices has at least one such path. The optimization asks for the fewest colors that can make that property hold across all pairs simultaneously.
Adjacent edges are allowed to have the same color. This is the central difference from proper edge coloring, where any two edges meeting at a vertex must differ. In a rainbow-connected graph, one unsuccessful path is harmless if a different path between the same endpoints uses distinct colors.
Compare this with the Minimum edge coloring calculator from a graph edge list. Minimize colors so every vertex pair has a path with all distinct edge colors. Adjacent edges may share colors here; proper edge coloring instead forbids equal colors on incident edges.
Represent vertices and links
Supply an unweighted simple undirected graph, using a vertex count and zero-based edge pairs. The graph must be connected, because colors cannot repair missing connectivity. Loops and repeated unordered pairs are rejected so that each row corresponds to one well-defined edge that receives one color.
No edge colors are required as input: the calculator searches for them. Returned color numbers are labels only, and renaming every color consistently leaves the property unchanged. The search exploits that symmetry by introducing color classes in canonical order instead of redoing equivalent assignments under all possible color names.
Search color counts in increasing order
The algorithm first tests whether one color suffices, then two, and continues until a valid assignment is found. For each candidate count, it exhausts canonical edge-color assignments. The first feasible count is therefore optimal if all smaller searches have completed successfully.
For each assignment, the verifier searches routes while remembering the colors already used. An extension that would repeat a color is forbidden. A vertex-and-color-mask state records the information needed for future extensions, and the resulting route supplies a witness for the corresponding endpoint pair rather than only a yes-or-no claim.
Why the four-cycle needs two colors
With one color, a rainbow path can contain at most one edge. Opposite vertices of a four-cycle are not adjacent, so they cannot be joined by a one-edge path; one color is impossible. Two colors are sufficient because every opposite pair has a two-edge alternative using both colors.
In the displayed default coloring, three consecutive cycle edges use color 0 and the remaining edge uses color 1. Some length-two routes repeat color 0 and fail, but their alternate routes use 0 and 1 and succeed. This example makes clear why proper coloring and checking only one chosen shortest path would answer a different question.
Useful exact families and lower bounds
For a complete graph with at least two vertices, one color suffices because every pair is adjacent. In a tree, each pair has a unique path, and every pair of edges lies together on some vertex-to-vertex path. Consequently every tree edge must receive its own color.
The ordinary graph diameter is a lower bound on rainbow connection number: a rainbow path with k colors has at most k edges, while some endpoint pair requires at least the diameter in any route. That bound is not always attained, so it is a check on the answer rather than a substitute for the exact coloring search.
Inspect the path certificates
For every unordered pair, the output lists a vertex route and its edge colors. Check that consecutive vertices share a listed edge and that the corresponding color list has no duplicates. The witness does not need to be a shortest uncolored route because ordinary rainbow connection only requires existence of some rainbow path.
Strong rainbow connection would insist that a rainbow route also be shortest in the original graph. That stronger requirement is not implemented here. A color assignment can pass the ordinary test and fail the strong one, so the two names should not be treated as interchangeable when comparing references or other calculators.
Know when the computation stops
The search can grow quickly even on a small graph, so this page has both graph-size limits and an explicit search-state cap. If the cap is reached before optimality is proved, it returns an unresolved error instead of presenting the best assignment seen so far as a certified minimum.
This is a deterministic combinatorial model, not a probability of route failure or a bandwidth assignment. Real networks may impose directed links, capacities or interference constraints that colors alone do not represent. Use the exact colored-path result as a structural property of the entered graph, and evaluate operational constraints separately.
A few questions, answered
Can incident edges share a color?
Yes. Ordinary rainbow connection requires a suitable rainbow path for each pair, not proper coloring at every vertex.
Must the rainbow path be shortest?
No. That additional requirement defines strong rainbow connection, which this page does not compute.
Why does a tree need a different color on every edge?
Its paths are unique, and any two edges occur together on some path; repeating their color would block that pair.
What happens when the search cap is reached?
The calculation is unresolved. No heuristic color count is labeled the proven minimum.