USACO 2019 US Open Contest, Silver Problem 3 Fence Planning
Farmer John's?NN?cows, conveniently numbered?1…N1…N?(2≤N≤1052≤N≤105), have a complex social structure revolving around "moo networks" --- smaller groups of cows that communicate within their group ...