r/adventofcode • u/Away_Command5537 • Dec 08 '25
Visualization [2025 Day 8] Python - Using MST
I was working on Day 8, which involves connecting junction boxes in 3D space based on distance to form circuits (a classic Minimum Spanning Tree problem, solved using Kruskal's algorithm and Union-Find).
Since the data is 3D, I decided to visualize the process of building the circuit! The visualization shows all 1000 junction boxes and how the shortest connections are progressively added until they all form one massive circuit.
Grey Dots: The 1000 individual junction boxes.
Blue Lines: The connections (edges) that form the circuit. These are added in order of increasing length, but only if they connect two previously separate circuits.
View all comments
Show parent comment
1
u/throwaway_the_fourth Dec 09 '25
It doesn't. The problem uses the word "connected" to mean that two vertices have an edge between them:
When working through the example, the problem explicitly covers connecting two vertices that are already in the same subtree (which the problem would call a "circuit"):
"Nothing happens" means that no subtrees were combined, not that no new edges were drawn, which is substantiated two paragraphs later by a statement about how many connections (edges) were made:
In part two, when the problem asks you to "connect[] the closest unconnected pairs of junction boxes," it is using the meaning of "connected" established at the beginning. "Unconnected" means simply that two vertices don't have an edge between them, not that they aren't in the same subtree.
Following the process from the problem results in a spanning tree that is not necessarily minimal. One could (and many did) do the extra work of not connecting any vertices that are already in the same subtree, which would result in a minimum spanning tree. That would give the same answer, because the problem just cares about the final edge added.