Find the cheapest simple path to every reachable node
Original fictional practice · CC BY 4.0 · 2026-11-11

TASK
Start at graph node 1. Paths must not repeat a node. Return node,min_cost for reachable destinations excluding 1, choosing minimum total edge weight over all simple paths. Sort node.

OUTPUT
node, min_cost

RULES
Start at graph node 1. Paths must not repeat a node. Return node,min_cost for reachable destinations excluding 1, choosing minimum total edge weight over all simple paths. Sort node.
Return exactly the declared columns and order. Money uses integer cents; all time values are elapsed UTC minutes unless a field is explicitly a day index. NULL is unknown and differs from numeric zero.
These are original fictional records and exercise policies. All source tables in this case are included in the downloadable pack.

FIELD DICTIONARY
nodes:
  id INTEGER — Stable record or business key; retain its declared type.
  parent INTEGER — Exact integer measurement; use the task rule for units and ordering.
  cost INTEGER — Exact integer measurement; use the task rule for units and ordering.

edges:
  src INTEGER — Exact integer measurement; use the task rule for units and ordering.
  dst INTEGER — Exact integer measurement; use the task rule for units and ordering.
  weight INTEGER — Exact integer measurement; use the task rule for units and ordering.

parts:
  parent TEXT — Literal text label or key; comparisons use SQLite binary text semantics.
  child TEXT — Literal text label or key; comparisons use SQLite binary text semantics.
  qty INTEGER — Exact integer measurement; use the task rule for units and ordering.

METHOD
Start at graph node 1. Paths must not repeat a node. Return node,min_cost for reachable destinations excluding 1, choosing minimum total edge weight over all simple paths. Sort node.
Inspect the source grain, keys and ties before writing the query. Use the worked SQL and complete expected CSV to review any mismatch.

COMMON WRONG TURN
Fewest hops is not necessarily lowest weighted cost.

RESULT CHECK
The independent JavaScript solver and actual SQLite reference must agree on every output cell.

Use setup.sql in a fresh SQLite database and run your own SELECT or WITH. reference.sql and expected.csv contain the full worked answer. All CSVs have UTF-8 headers; empty output fields represent NULL. The browser executes SQLite, not Excel formulas. No spreadsheet function engine is claimed.
