On this page
Two graphs can look different on paper and still be the same graph with the vertices renamed. Trying relabellings is hopeless: 6 vertices already allow 6! = 720. Colour refinement, the one-dimensional Weisfeiler–Leman test, replaces that search with a few rounds of bookkeeping.
What is Weisfeiler–Leman colour refinement?
Boris Weisfeiler and Andrey Leman described the method in 1968, in a paper on reducing a graph to a canonical form (overview with the original citation). Colour refinement repeatedly updates the colour of each vertex according to the multiset of colours of its neighbours.
The rules:
Start with every vertex the same colour.
Each round, give every vertex a new colour set by its old colour plus the multiset of its neighbours' old colours. A multiset keeps repeats: {1, 1, 2} is not {1, 2, 2}.
Run both graphs with one shared list of new colours, and count the vertices of each colour.
Stop when a round splits no colour class.
If the colour counts ever differ, the graphs are not isomorphic; if they end up the same, the test is inconclusive. A survey by Morris and colleagues notes that the colouring stops changing within n rounds for graphs on n vertices, and that Cardon and Crochemore showed in 1982 that it can be computed in O(n + m log n) time, where m is the number of edges.
How does colour refinement separate two graphs?
Take two trees, each with 6 vertices and 5 edges. In tree A, a centre c has two leaves and a path c–a–b–leaf. In tree B, a centre c has one leaf and two short arms, c–x–leaf and c–y–leaf. Both have the degree sequence 3, 2, 2, 1, 1, 1, so counting degrees will not split them.
Round 1. All vertices start alike, so each new colour is just the vertex's degree. Each tree gets one vertex coloured 3, two coloured 2 and three coloured 1. Still tied.
Round 2. Write each vertex as (own colour; neighbours' colours).
Tree A: c is (3; 1, 1, 2). a is (2; 2, 3). b is (2; 1, 2). The two leaves on c are (1; 3). The leaf on b is (1; 2).
Tree B: c is (3; 1, 2, 2). x and y are both (2; 1, 3). The leaf on c is (1; 3). The other two leaves are (1; 2).
The centre of A sees {1, 1, 2}; the centre of B sees {1, 2, 2}. The colour counts now differ, so the trees are not isomorphic. After round 2, tree A has five colour classes and tree B has four, which you can see in the diagram above.
Which graphs can the Weisfeiler–Leman test not tell apart?
The same survey states that the test cannot distinguish any two regular graphs with the same number of vertices and the same degree. Its first example: a 6-cycle against two separate triangles. Every vertex has degree 2, so every round gives every vertex (2; 2, 2). Nothing splits, yet one graph is connected with no triangles and the other has two pieces and two triangles.
Such failures are rare: the survey notes that the test almost surely identifies a random graph, a consequence of a 1980 result by Babai, Erdős and Selkow (SIAM Journal on Computing). For the symmetric hard cases, fall back on other invariants: connectedness, triangle counts, the ones in our guide to telling two graphs apart, the chromatic polynomial, or the eigenvalues of the graph Laplacian.
How is Weisfeiler–Leman linked to graph neural networks?
A message-passing graph neural network (GNN) updates a vector at each vertex, layer by layer, from its own vector and its neighbours' vectors: colour refinement with numbers for colours.
Xu, Hu, Leskovec and Jegelka showed that popular GNN variants cannot learn to distinguish certain simple graph structures, and designed an architecture as powerful as the Weisfeiler–Leman test (How Powerful are Graph Neural Networks?). Morris and colleagues proved that GNNs have the same expressiveness as the one-dimensional test in distinguishing non-isomorphic graphs, so both share the same shortcomings (AAAI 2019). So when every vertex starts with the same features, a standard message-passing network gives the 6-cycle and the two triangles the same output.
How do you practise colour refinement?
Compare vertex count, edge count and degree sequence first.
Run the rounds in a table, both graphs together.
Stop when the counts differ (not isomorphic) or no class splits (inconclusive).
If you are stuck on regular graphs, switch to an invariant the test cannot see, such as triangles.
If words such as degree, regular graph or isomorphism still feel loose, the Fermi Concept Library has a lesson for every concept in mathematics and computing, each with its place in the map. For practice, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.
Run the 6-cycle and two triangles once by hand: watching the colours refuse to split shows what the test cannot see.



