Project Euler Lab - Problem 716

#716 - Grid Graphs

● ResearchOfficial difficulty: 64%NetworksTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

Consider a directed graph made from an orthogonal lattice of \(H\times W\) nodes. The edges are the horizontal and vertical connections between adjacent nodes. \(W\) vertical directed lines are drawn and all the edges on these lines inherit that direction. Similarly, \(H\) horizontal directed lines are drawn and all the edges on these lines inherit that direction.

Two nodes, \(A\) and \(B\) in a directed graph, are strongly connected if there is both a path, along the directed edges, from \(A\) to \(B\) as well as from \(B\) to \(A\). Note that every node is strongly connected to itself.

A strongly connected component in a directed graph is a non-empty set \(M\) of nodes satisfying the following two properties:

  • All nodes in \(M\) are strongly connected to each other.
  • \(M\) is maximal, in the sense that no node in \(M\) is strongly connected to any node outside of \(M\).

There are \(2^H\times 2^W\) ways of drawing the directed lines. Each way gives a directed graph \(\mathcal{G}\). We define \(S(\mathcal{G})\) to be the number of strongly connected components in \(\mathcal{G}\).

The illustration below shows a directed graph with \(H=3\) and \(W=4\) that consists of four different strongly connected components (indicated by the different colours).

Define \(C(H,W)\) to be the sum of \(S(\mathcal{G})\) for all possible graphs on a grid of \(H\times W\). You are given \(C(3,3) = 408\), \(C(3,6) = 4696\) and \(C(10,20) \equiv 988971143 \pmod{1\,000\,000\,007}\).

Find \(C(10\,000,20\,000)\) giving your answer modulo \(1\,000\,000\,007\).

This problem is taken from Project Euler, Problem 716.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=716. Published Sunday, 17th May 2020, 11:00 am. Solved by 265 members at time of mirroring.

Why this is useful

Algorithmic Development. Graph/state-space search transfers to routing, dependency resolution, and execution-path optimisation (Phases 16, 17).

We classify relevance honestly - not every Euler problem is a trading application.

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier C - reduced scale in browser; full scale in notebook
Browser runs a reduced, clearly-labelled educational scale; the original scale is provided in a local notebook.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.