Editorial for COCI '11 Contest 2 #2 Okret
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 ) that has only one neighbor (), then by moving from to we get stuck in , i.e. our only way out is by a 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