Editorial for COCI '11 Contest 2 #2 Okret


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.

There are dead-ends inside the given city if and only if there are road surface cells that are adjacent to only one other road surface cell.

Let's prove this. If there is a road surface cell (let's call it A) that has only one neighbor (B), then by moving from B to A we get stuck in A, i.e. our only way out is by a 180 degrees turn, which means that dead-end exists.

If there is no such cell, then we can exit every cell using some direction other than the one by which we came in. Let's start at some road surface cell using any direction and proceed in the following matter: leave the cell we are currently in by using direction other than the one by which we came in. Since there is a finite number of free cells, we will sooner or later enter some cell which we already visited. When this happens, one of these two statements is true: either we returned to the starting point, or we can return to the starting point using the same path. In both cases, it's possible to get back to the starting point, which concludes our proof.

The described solution is very easily implemented: for each road surface cell count the number of free cells.


Comments

There are no comments at the moment.