Approach hintTry it first, then revealHide
Join two drifts with an edge when they share an x or a y coordinate. Each new drift can link two components, so count the connected components with DFS and answer one less than that count.
Join two drifts with an edge when they share an x or a y coordinate. Each new drift can link two components, so count the connected components with DFS and answer one less than that count.