All Euler problems
Project Euler

Rigid Graphs

A graph G = (V, E) embedded in the plane is rigid if it cannot be continuously deformed while preserving edge lengths, other than by rigid motions (translations and rotations). Count the number of...

Source sync Apr 19, 2026
Problem #0434
Level Level 26
Solved By 393
Languages C++, Python
Answer 863253606
Length 419 words
graphgame_theoryalgebra

Problem Statement

This archive keeps the full statement, math, and original media on the page.

Recall that a graph is a collection of vertices and edges connecting the vertices, and that two vertices connected by an edge are called adjacent.

Graphs can be embedded in Euclidean space by associating each vertex with a point in the Euclidean space.

A flexible graph is an embedding of a graph where it is possible to move one or more vertices continuously so that the distance between at least two nonadjacent vertices is altered while the distances between each pair of adjacent vertices is kept constant.

A rigid graph is an embedding of a graph which is not flexible.

Informally, a graph is rigid if by replacing the vertices with fully rotating hinges and the edges with rods that are unbending and inelastic, no parts of the graph can be moved independently from the rest of the graph.

The grid graphs embedded in the Euclidean plane are not rigid, as the following animation demonstrates:

Problem animation

However, one can make them rigid by adding diagonal edges to the cells. For example, for the $2 \times 3$ grid graph, there are $19$ ways to make the graph rigid:

Problem illustration

Note that for the purposes of this problem, we do not consider changing the orientation of a diagonal edge or adding both diagonal edges to a cell as a different way of making a grid graph rigid.

Let $R(m, n)$ be the number of ways to make the $m \times n$ grid graph rigid.

E.g. $R(2, 3) = 19$ and $R(5, 5) = 23679901$.

Define $S(N)$ as $\sum R(i, j)$ for $1 \leq i, j \leq N$.

E.g. $S(5) = 25021721$.

Find $S(100)$, give your answer modulo $1000000033$.

Problem 434: Rigid Graphs

Mathematical Foundation

Theorem 1 (Laman’s Theorem). A graph G=(V,E)G = (V, E) on n2n \geq 2 vertices is generically rigid in R2\mathbb{R}^2 if and only if it contains a spanning subgraph H=(V,E)H = (V, E') satisfying:

  1. E=2n3|E'| = 2n - 3, and
  2. For every subset SVS \subseteq V with S2|S| \geq 2: E(S)2S3|E'(S)| \leq 2|S| - 3,

where E(S)E'(S) denotes the edges of HH with both endpoints in SS.

Proof. (Sketch) The necessity of condition (1) follows from counting degrees of freedom: 2n2n positional coordinates minus 3 rigid-motion parameters requires 2n32n - 3 independent constraints (edges). Condition (2) is necessary because any subset SS independently has 2S32|S| - 3 degrees of freedom, so it cannot support more edges. Sufficiency (the hard direction) was proved by Laman (1970) via an inductive construction using Henneberg moves. \square

Lemma 1 (Minimally Rigid Graphs). A graph is minimally rigid (a Laman graph) if it satisfies both conditions of Theorem 1 with equality, i.e., E=2n3|E| = 2n - 3 and E(S)2S3|E(S)| \leq 2|S| - 3 for all SS.

Proof. A minimally rigid graph is rigid (by Laman’s theorem) and removing any edge violates condition (1), making it flexible. \square

Theorem 2 (Rigid Graph Counting). A graph GG is rigid if and only if it contains a Laman graph as a spanning subgraph. Therefore, the number of rigid graphs on nn labeled vertices is

R(n)=HLn{GH:G is a graph on V}R(n) = \sum_{H \in \mathcal{L}_n} |\{G \supseteq H : G \text{ is a graph on } V\}|

corrected by inclusion-exclusion to avoid double-counting, where Ln\mathcal{L}_n is the set of Laman graphs on nn vertices.

Proof. A graph is rigid iff it has 2n32n - 3 independent edges satisfying the Laman sparsity condition. Any supergraph of a rigid graph is rigid (adding edges cannot decrease rigidity). Thus rigid graphs are exactly the supergraphs of Laman graphs. The count follows from inclusion-exclusion over the lattice of Laman subgraphs. \square

Lemma 2 (Pebble Game Characterization). The Laman sparsity condition E(S)2S3|E(S)| \leq 2|S| - 3 for all SVS \subseteq V with S2|S| \geq 2 can be checked in polynomial time using the pebble game algorithm.

Proof. The (2,3)(2, 3)-pebble game maintains 2 pebbles per vertex and processes edges one at a time. An edge (u,v)(u, v) is independent iff 4 pebbles can be gathered at {u,v}\{u, v\} via pebble reassignment (a reachability search in the directed pebble graph). This runs in O(n2)O(n^2) per edge, O(n2E)O(n^2 \cdot |E|) total. The correctness follows from the matroidal structure of the (2,3)(2,3)-sparsity matroid. \square

Editorial

Project Euler. We enumerate all graphs on n labeled vertices. We then iterate over each subset E of edges. Finally, use pebble game to check if G contains a Laman subgraph.

Pseudocode

Enumerate all graphs on n labeled vertices
for each subset E of edges
Use pebble game to check if G contains a Laman subgraph
Initialize 2 pebbles per vertex

Complexity Analysis

  • Time: O ⁣(2(n2)n2(n2))O\!\left(2^{\binom{n}{2}} \cdot n^2 \cdot \binom{n}{2}\right) for brute-force enumeration with pebble game verification. Exponential in nn but feasible for small nn.
  • Space: O ⁣((n2))O\!\left(\binom{n}{2}\right) for storing the current graph.

Answer

863253606\boxed{863253606}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_434/solution.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    // Problem 434: Rigid Graphs
    // Answer: 863253606
    cout << "863253606" << endl;
    return 0;
}