The official solution uses DSU. How do I do this using DFS?

Link to the problem: http://www.usaco.org/index.php?page=viewproblem2&cpid=644

It’s described in the analysis …

Thanks again, Ben, for your help! :+1: