Problem 2316 · Medium
Join connected nodes with union-find, then count pairs that cross between components.
Open the interactive visualisation