Editorial for ICPC PACNW 2016 G - Maximum Islands


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

For any cloud touching existing land, it can't hurt to make that cloud water, so we can greedily assign those. So, let's assume there are no clouds adjacent to land.

Now, in an optimal solution, all islands from clouds will consist of a single square. Consider any optimal solution. If it has an island with more than one square, we can just convert one of those to water and still have the same number of islands.

So, we want to choose the maximum number of squares such that no two are adjacent. This sounds a lot like the maximum independent set problem.

This problem is normally NP-hard, but we can notice that the grid is bipartite.

We can also notice that the complement of an independent set is a vertex, so maximizing the size of an independent set is the same as finding the size of a minimum vertex cover.

Lastly, we can use Kőnig's Theorem to equate minimum vertex covers with maximum matchings in a bipartite graph. This can then be solved with flow.


Comments

There are no comments at the moment.