UVA 10004 - Bicoloring

The full problem description can be found here.
Java Code